eth_getCode
Fetches the compiled bytecode of smart contracts deployed on IoTeX One network. This method is crucial for contract verification, security auditing, and analyzing DeFi protocols on IoTeX's high-performance Layer 2 solution.
Parameters​
Parameter | Type | Required | Description |
---|---|---|---|
address | string | Yes | The 20-byte contract address (0x-prefixed hex string) |
blockNumber/blockTag | string | Yes | Block number in hex (e.g., "0x1b4") or block tag: "latest", "earliest", "pending", "safe", "finalized" |
Block Tags​
latest
- Most recent block in the canonical chainearliest
- Genesis blockpending
- Pending state/transactionssafe
- Latest safe head block (IoTeX)finalized
- Latest finalized block (IoTeX)
Returns​
Returns the contract bytecode as a hex-encoded string. Externally Owned Accounts (EOAs) return "0x".
Type | Description |
---|---|
string | Hex-encoded contract bytecode starting with "0x". Returns "0x" for EOA addresses |
Code Examples​
- cURL
- JavaScript
- Python
# Get bytecode for USDC contract on IoTeX
curl -X POST https://api-iotex-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
"latest"
],
"id": 1
}'
// Get bytecode for Uniswap V3 Router on IoTeX
const response = await fetch('https://api-iotex-mainnet.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getCode',
params: [
'0xE592427A0AEce92De3Edee1F18E0157C05861564',
'latest'
],
id: 1
})
});
const data = await response.json();
console.log('Uniswap Router bytecode:', data.result);
// Verify contract deployment
if (data.result === '0x') {
console.log('No contract found at this address');
} else {
console.log('Contract verified on IoTeX');
console.log(`Bytecode size: ${(data.result.length - 2) / 2} bytes`);
}
import requests
import json
# Get bytecode for GMX token contract on IoTeX
url = "https://api-iotex-mainnet.n.dwellir.com/YOUR_API_KEY"
payload = {
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a", # GMX token
"latest"
],
"id": 1
}
response = requests.post(url, json=payload)
result = response.json()
if result['result'] == '0x':
print("Address is an EOA")
else:
bytecode = result['result']
print(f"GMX Contract bytecode: {bytecode[:100]}...")
print(f"Contract size: {(len(bytecode) - 2) // 2} bytes")
# Check for proxy patterns
if "363d3d373d3d3d363d73" in bytecode:
print("Detected: Minimal proxy pattern")
elif "608060405234801561001057600080fd5b50" in bytecode:
print("Detected: Standard Solidity contract")
Response Example​
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x60806040523480156200001157600080fd5b50600436106200014d5760003560e01c80637ecebe0011620000ca5780639dc29fac116200008f5780639dc29fac146200032f578063a457c2d714620003565780639d8e21701462000384578063dd62ed3e1462000390578063f2d5d56b14620003bd5780639711715a14620003ca576200014d565b80637ecebe0014620002a857806386fe8b43146200022a5780638da5cb5b1462000253578063a9059cbb1462000265578063987e52891462000292576200014d565b8063313ce567116200011257806339509351146200020b5780634334614a1462000233578063456082d6146200025a57806370a08231146200026757806379cc67901462000285576200014d565b806306fdde031462000152578063095ea7b3146200017a57806318160ddd14620001a157806323b872dd14620001b9578063313ce56714620001e0575b600080fd5b6200015c620003d1565b6040516200017191906200189b565b60405180910390f35b620001856200018b3660046200191e565b62000465565b604051620001969190620018f0565b60405180910390f35b620001ab6200047d565b60405161019691906200195a565b620001c4620001c93660046200196e565b62000487565b604051620001969190620018f0565b620001ea620004cc565b60405162000201919062001a9c565b60405180910390f35b6200021e620002193660046200191e565b620004d5565b604051620001969190620018f0565b6200023e62000520565b60405162000201919062001a9c565b6200025d62000529565b6040516200017191906200189b565b620001856200027636600462001c3c565b62000537565b6200029962000294366004620018df565b6200055f565b005b620002a0620002a136600462001a36565b62000577565b005b620002bc620002b736600462001a36565b6200057d565b60405162000201919062001a9c565b620002a0620002d336600462001b47565b6200058f565b620002a0620002e73660046200191e565b62000611565b620002a0620002f93660046200191e565b62000667565b620003066200030b36600462001c3c565b620006bd565b604051620001969190620018f0565b620003326200032836600462001d6b565b620006e7565b6040516200017191906200189b565b6200034762000342366004620018df565b62000745565b604051620001969190620018f0565b620003676200036236600462001a36565b6200075c565b6040516200017191906200189b565b620003906200038f36600462001a36565b62000774565b60405162000201919062001a9c565b620003a6620003a136600462001e70565b6200077e565b60405162000201919062001a9c565b620003ca620003c936600462001e70565b620007a9565b6040516200017191906200189b565b6060600380546200041490620020ad565b80601f01602080910402602001604051908101604052809291908181526020018280546200044290620020ad565b8015620004935780601f10620004675761010080835404028352916020019162000493565b820191906000526020600020905b8154815290600101906020018083116200047557829003601f168201915b5050505050905090565b6000620004a2338484620007d4565b50600192915050565b6000600254905090565b6000620004c684848462000868565b50600192915050565b60006012905090565b6000620004e2336200056a565b620004ff576040516200050a9062002164565b60405180910390fd5b6200050c338484620007d4565b506200051933846200090e565b5060019392505050565b60006009905090565b6060600480546200041490620020ad565b60006200054c826200054662000ab2565b62000abb565b1562000559576000620005ab565b620005658282620006bd565b825b9392505050565b6000806200057c8362000ad6565b9050919050565b60006200058962000af0565b92915050565b620005b262000596620004cc565b8360ff1614620005a8576040516200050a9062002164565b620005b462000596620004cc565b835114620005cd576040516200050a9062002164565b620005d8846200056a565b620005e5576040516200050a9062002164565b6000620005f285620004cc565b9050816200060762000b0a565b0362000613578062000615565b825b9150509392505050565b620006296200062362000b0a565b8262000b14565b6200063682858562000b2e565b620006423383620007d4565b6200064f33838362000b39565b6200065b338362000b4d565b6200066633620005ab565b505050565b620006846200067e62000b0a565b8262000b14565b620006903382620007d4565b6200069c338262000b4d565b620006a933838362000b39565b620006b533826200090e565b620006bb620005ab565b5050565b6000620006ca836200056a565b620006d7576000620005ab565b620006e38383620007d4565b5060019392505050565b6060620006fa8262000b64565b6200070d57620007088262000b6e565b62000717565b620007178262000b6e565b604051602001620007299190620020ed565b6040516020818303038152906040529050919050565b600062000753338462000ab2565b50600192915050565b60006200076a826200056a565b1590505b919050565b600062000774826200056a565b9050919050565b6000620007928362000b64565b620007a057826002620007a3565b82825b9392505050565b6060620007b68262000b6e565b604051602001620007c89190620020ed565b6040516020818303038152906040529050919050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156200081d576040516200050a906200217b565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415620008635760405162000863906200217b565b620008508383836001600160a01b038416600090815260016020526040902062000857565b505050565b6000620008758484620004cc565b90508015620008a957620008a962000897866200047d565b838362000b39565b620008b562000b0a565b0362000857565b6000620008c7866200047d565b90508082111562000903576040516200050a906200217b565b620008f08685620008e0848462000c7e565b8562000c8962000b39565b620008fc868262000c93565b5050505050565b600062000856856200047d565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141562000954576040516200050a906200217b565b6000600160a01b038316600090815260006020526040902062000978565b90508181016200098a868362000c9d565b111562000998576040516200050a906200217b565b6000600160a01b0383166000908152600060205260409020620009bc565b905081811015620009d0576040516200050a906200217b565b620009dd838383620009e7565b6200096685620009f2565b505050565b600080820190508091505092915050565b6000806000808462000a1662000a0562000b0a565b8516600090815260066020526040902062000a21565b90506000198114801562000a3057508083115b1562000a4957600019915062000a47848262000ca7565b505b5091935091505050565b6000818152600660205260408120805491829162000a758462002119565b919050819055905090508382111562000a8f57600062000a91565b825b91508181111562000aa257600062000aa4565b815b6001555050919050565b600062000ab6308362000cb1565b905090565b60006200076a848462000cc7565b60006200076a8262000cd1565b60006200076a8262000cde565b60006008905090565b60006200076a826200056a565b5050565b600081831062000b27576000620005ab565b62000566828462000cfb565b6000808262000b3f8562000d25565b945094505050509392505050565b600062000b5b838362000d30565b50600192915050565b60006200076a8262000da2565b6060600062000b7d8362000db6565b60010190506000816001600160401b0381111562000b9f5762000b9f6200204b565b6040519080825280601f01601f19166020018201604052801562000bca576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508462000bd45750505050919050565b600080820391508162000c8f576040516200050a906200217b565b92915050565b60006200076a828462000e7b565b60006200076a828462000ea4565b6000620008f03362000b0a565b600062000cb883838362000ec0565b505050565b505050565b60006200076a828462000f20565b60006200076a6008620005ab565b60006200076a8262000f2f565b60006200076a8262000f9b565b60005b8383101562000d215780820151838201526020016200076a565b50505050565b600062000d2a8262000fad565b92915050565b60008060006200076a8462000afe57600162000d4d838362000afe565b62000d5a8601038562000f70565b905060026040516200062391810190618013905090565b600062000d7d828462001017565b90508362001017811115620008f05760405162000859906200217b565b90508062000567565b60006200076a8262001092565b60006200076a826200109e565b600080600019830162000ddb5760405162000859906200217b565b600a846040516200062391810190818152905090565b600062000e0a8462001036565b90508062000e19878762001048565b1115620008f0576040516200085990629002173565b60008262000e4962000e3b858562001065565b84620006619062001072565b1162000e5757600062000e59565b835b905062000e6b8582601f62001085565b111562000e7957600062000e7b565b815b9250505092915050565b600062000e968383601f62001085565b905062000566848262001085565b60006200076a838362001091565b6000828282038262000ed462000d7d82876200109e565b111562000ee257600062000ee4565b815b905060005b8481101562000f175782810183820162000f05818262001085565b62000f1081621008565b9350620008f0565b50505092915050565b600062000566828462001021565b60408051602081019091526000815260006001600160a01b0383161562000f6057620005668362001034565b62000566826200104a565b60006200076a828462001067565b60006200076a82620010a2565b60006200076a826200071b565b600062000fb88262001036565b905060405162000859906002019150565b505050565b600080600019830162000fe25760405162000859906200217b565b600062000567838562001072565b60006200076a8262001092565b600062000566828462001085565b600062000566848262001075565b60006200076a8262001067565b60006200076a8262001098565b600062000566828462001091565b600062000566838362001096565b600062000566838362001037565b60006200076a6008620005ab565b600062000566828462001093565b60006200076a828462001036565b600062000566828462001095565b600062000566828462001092565b600062000566828462001093565b6002620005ab8262001098565b600062000566848462001096565b600062000566838362001092565b600062000566848462001092565b600062000566838362001095565b600062000566838362001093565b90509092915050565b6200105e8162001036565b600062000566829062000592565b80356200076a8162002217565b80356200076a8162002208565b600062001089838562001093565b90506200109681620010ab565b5050565b8092919050565b506000919050565b90565b505056fea2646970667358221220f8b4e6c5b7d1a4c3f6e9d8b2a1c0f9e8d7c6b5a4938271605958473829571aef64736f6c63430008130033"
}
Important Notes​
EOA vs Contract Addresses​
- Contract addresses: Return the deployed smart contract bytecode
- EOA addresses: Return "0x" as they contain no executable code
- Essential for distinguishing between user accounts and smart contracts
Use Cases​
- DeFi protocol analysis: Examine deployed protocol logic on IoTeX
- Contract verification: Validate source code against deployed bytecode
- Security auditing: Analyze contract patterns and potential vulnerabilities
- Proxy contract detection: Identify upgradeable proxy implementations
IoTeX-Specific Considerations​
- IoTeX One uses Optimistic Rollup technology for scalability
- Bytecode format is fully compatible with Ethereum
- Lower gas costs enable complex smart contract interactions
- Full EVM compatibility ensures seamless contract deployment
Need help? Contact our support team or check the IoTeX documentation.