eth_getCode
Retrieves the compiled bytecode of smart contracts deployed on Unichain's DeFi-optimized network. This method is crucial for DEX protocol analysis, AMM verification, and DeFi development on Unichain's high-performance blockchain infrastructure.
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 (Unichain)finalized
- Latest finalized block (Unichain)
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 a DeFi contract on Unichain
curl -X POST https://api-unichain-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24",
"latest"
],
"id": 1
}'
// Get bytecode for Uniswap V4 Pool on Unichain
const response = await fetch('https://api-unichain-mainnet.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getCode',
params: [
'0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640',
'latest'
],
id: 1
})
});
const data = await response.json();
console.log('Pool contract bytecode:', data.result);
// Verify contract deployment
if (data.result === '0x') {
console.log('No contract found at this address');
} else {
console.log('Contract verified on Unichain');
console.log(`Bytecode size: ${(data.result.length - 2) / 2} bytes`);
}
import requests
import json
# Get bytecode for DEX Router contract on Unichain
url = "https://api-unichain-mainnet.n.dwellir.com/YOUR_API_KEY"
payload = {
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45", # Example DEX Router
"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"DEX Router bytecode: {bytecode[:100]}...")
print(f"Contract size: {(len(bytecode) - 2) // 2} bytes")
# Check for common 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": "0x608060405234801561001057600080fd5b50600436106101005760003560e01c80637ecebe0011610097578063d505accf11610066578063d505accf146101f8578063dd62ed3e1461020b578063f2fde38b1461021e578063fca3b5aa1461023157610100565b80637ecebe00146101b257806395d89b41146101c55780639dc29fac146101cd578063a9059cbb146101e557610100565b8063313ce567116100d3578063313ce5671461017057806340c10f191461017f57806370a0823114610192578063715018a6146101aa57610100565b806306fdde0314610105578063095ea7b31461012357806318160ddd1461014657806323b872dd1461015d575b600080fd5b61010d610244565b60405161011a91906112a5565b60405180910390f35b6101366101313660046112ea565b6102d6565b604051901515815260200161011a565b61014f60025481565b60405190815260200161011a565b61013661016b366004611314565b6102f0565b6040516012815260200161011a565b61013661018d3660046112ea565b610314565b61014f6101a0366004611350565b6001600160a01b031660009081526020819052604090205490565b6101b2610328565b005b61014f6101c0366004611350565b61033c565b61010d61035a565b6101366101db3660046112ea565b610369565b6101366101f33660046112ea565b61037d565b6101b261020636600461136b565b61038b565b61014f6102193660046113de565b6104ee565b6101b261022c366004611350565b610519565b6101b261023f366004611350565b61058f565b60606003805461025390611411565b80601f016020809104026020016040519081016040528092919081815260200182805461027f90611411565b80156102cc5780601f106102a1576101008083540402835291602001916102cc565b820191906000526020600020905b8154815290600101906020018083116102af57829003601f168201915b5050505050905090565b6000336102e48185856105b9565b60019150505b92915050565b6000336102fe8582856106dd565b610309858585610757565b506001949350505050565b60006103203383610900565b506001919050565b6103306109d6565b61033a6000610a30565b565b6001600160a01b0381166000908152600560205260408120546102ea565b60606004805461025390611411565b60006103753383610a82565b506001919050565b6000336102e4818585610757565b834211156103e05760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e6500000060448201526064015b60405180910390fd5b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886104fb565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050600061046982610bb4565b9050600061047982878787610be2565b9050896001600160a01b0316816001600160a01b0316146104dc5760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e6174757265000060448201526064016103d7565b6104e78a8a8a6105b9565b5050505050505050565b600092915050565b6001600160a01b0387166000908152600560209081526040808320549051909161052f918a918a918a918a918a918a9161144b565b60405180910390208a8a8a8a8a8a604051602001610553969594939291906114d8565b60405160208183030381529060405280519060200120905061058581610579610c0a565b83919061ffff16610be2565b9998505050505050505050565b6105976109d6565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03831661061b5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016103d7565b6001600160a01b03821661067c5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016103d7565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006106e984846104ee565b90506000198114610751578181101561..."
}
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 wallets and smart contracts
Use Cases​
- DEX protocol analysis: Examine AMM pool logic and routing contracts
- DeFi verification: Validate lending protocols and yield strategies
- Security auditing: Analyze contract patterns and potential vulnerabilities
- Cross-chain verification: Compare deployed contracts across chains
Unichain-Specific Considerations​
- Unichain is optimized for DeFi operations and MEV protection
- Full EVM compatibility ensures seamless contract deployment
- Enhanced performance for complex DeFi interactions
- Lower gas costs enable efficient contract execution
- Built-in hooks for cross-chain liquidity management
Need help? Contact our support team or check the Unichain documentation.