eth_getCode
curl --request POST \
--url https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
"latest"
]
}
'import requests
url = "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": ["0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82", "latest"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'eth_getCode',
params: ['0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82', 'latest']
})
};
fetch('https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_getCode',
'params' => [
'0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82',
'latest'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab"
payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getCode\",\n \"params\": [\n \"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82\",\n \"latest\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getCode\",\n \"params\": [\n \"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82\",\n \"latest\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getCode\",\n \"params\": [\n \"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82\",\n \"latest\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": {}
}BNB node API
eth_getCode | BNB Chain
BNB API method that retrieves the compiled bytecode of a smart contract, providing its address as a parameter. BNB Chain via Chainstack.
POST
/
35848e183f3e3303c8cfeacbea831cab
eth_getCode
curl --request POST \
--url https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab \
--header 'Content-Type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
"latest"
]
}
'import requests
url = "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": ["0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82", "latest"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'eth_getCode',
params: ['0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82', 'latest']
})
};
fetch('https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_getCode',
'params' => [
'0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82',
'latest'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab"
payload := strings.NewReader("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getCode\",\n \"params\": [\n \"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82\",\n \"latest\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab")
.header("Content-Type", "application/json")
.body("{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getCode\",\n \"params\": [\n \"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82\",\n \"latest\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://bsc-mainnet.core.chainstack.com/35848e183f3e3303c8cfeacbea831cab")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": 1,\n \"jsonrpc\": \"2.0\",\n \"method\": \"eth_getCode\",\n \"params\": [\n \"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82\",\n \"latest\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "<string>",
"id": 123,
"result": {}
}BNB API method that retrieves the compiled bytecode of a smart contract, providing its address as a parameter. This method returns a hexadecimal string representing the smart contract’s bytecode.
Developers can use this bytecode to verify whether a smart contract is legitimate and ensure that it performs its intended functions.
The following example retrieves the compiled bytecode from the CAKE token smart contract.
When called against a block older than the latest ~128 blocks, this method is treated as an archive request (2 RUs instead of 1 RU). See request units.
Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.
Parameters
-
address— the address of the smart contract to query. -
quantity or tag— the integer of a block encoded as hexadecimal or the string with:latest— the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.safe— the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or an instance of severe propagation latency.finalized— the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, and it would require at least 1/3 of the staked amount to be burned.earliest— the earliest available or genesis block.pending— the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.
Response
data — the compiled bytecode of a smart contract. Returns 0x if the address is not associated with a smart contract.
eth_getCode code examples
The following example retrieves the compiled bytecode from the CAKE token smart contract.
const ethers = require('ethers');
const NODE_URL = "CHAINSTACK_NODE_URL";
const provider = new ethers.JsonRpcProvider(NODE_URL);
const getCode = async (address, block) => {
const code = await provider.send("eth_getCode", [address, block]);
console.log(code);
};
getCode("0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82", "latest")
from web3 import Web3
node_url = "CHAINSTACK_NODE_URL"
code = web3.eth.get_code("0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82", "latest")
print(web3.to_hex(code)) # Convert the Bytes result into HEX.
Use case
A practical use case for theeth_getcode method is verifying whether an address is associated with a smart contract. This can be particularly useful for blockchain explorers, auditors, and DApp developers, who must ensure that the account they interact with is legitimate.Last modified on June 25, 2026
Was this page helpful?