L0vdL0vd

eth_getCode

Returns the bytecode deployed at an address at a given block.

Архив · Работает на любом прошлом блоке

Returns "0x" for externally owned accounts and for contracts not yet deployed at that block.

curl https://eth.l0vdinfra.com/YOUR_KEY \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jsonrpc":"2.0","id":1,"method":"eth_getCode","params":["0xdAC17F958D2ee523a2206206994597C13D831ec7","0x1208a5f"]}'

Пример ответа

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x606060405260043610610196576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde031461019b5780630753c30c14610229578063095ea7b3146102625780630e136b19146102a4578063…"
}

Длинные массивы и hex-строки в примере сокращены.

Параметры и свой эндпоинт

Параметры

addressstringобязательный
20-byte address, hex encoded.
blockstringобязательный
Block number in hex (e.g. "0x1208a5f") or a tag: "latest", "safe", "finalized", "earliest" or "pending". L0vd endpoints run archive nodes, so any historical block works.

Возвращает

string Runtime bytecode, hex encoded.

Когда использовать

Check whether an address is a contract and read its runtime bytecode at a block.

With a past block, learn when a contract was deployed (binary-search for the first block where code is not 0x) or what a proxy pointed to before an upgrade.

Как читать ответ

"0x" means no code: an externally owned account, a contract not yet deployed, or one destroyed at that block.

Otherwise the hex string is the deployed runtime bytecode, not the constructor code you compiled.

Советы

  • Bytecode of large contracts is tens of kilobytes; fetch it once and cache it by address and code hash.
  • For upgradeable proxies read the implementation slot with eth_getStorageAt (EIP-1967: 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc).

Связанные методы