gen_getContractCode
Retrieves the code of a deployed GenLayer intelligent contract at a specific block height and transaction status.
Method: gen_getContractCode
Parameters:
request(object, required): The contract code request parametersaddress(string, required): The contract address to queryblockNumber(string, optional): The block number to query at (hex-encoded). If not provided, uses latest blockstatus(string, optional): The transaction status filter ("finalized"or"decided"). If not provided, uses decided state
Returns: Base64-encoded contract code
Limits:
| Limit | Default | Config key |
|---|---|---|
| Contract bytes read per call | 16 MB | node.rpc.contract_read_max_bytes |
The node reads the contract's code slot directly, so the cost of a call is proportional to the code it returns rather than to everything the contract stores. The limit is a backstop above that: a contract whose declared code length exceeds it is refused before the bytes are read. Operators may reduce it; 0 or less disables it.
Example Request - Latest Decided State:
{
"jsonrpc": "2.0",
"method": "gen_getContractCode",
"params": [
{
"address": "0x73ca5a2b51edf506ceaf110a41780ec51294d89f"
}
],
"id": 1
}Example Request - Specific Block and Status:
{
"jsonrpc": "2.0",
"method": "gen_getContractCode",
"params": [
{
"address": "0x73ca5a2b51edf506ceaf110a41780ec51294d89f",
"blockNumber": "0x151ec5",
"status": "finalized"
}
],
"id": 1
}Example Response:
{
"jsonrpc": "2.0",
"result": "IyB7ICJEZXBlbmRzIjogInB5LWdlbmxheWVyOnRlc3QiIH0KCmZyb20gZ2VubGF5ZXIgaW1wb3J0ICoKCgpjbGFzcyBTdG9yYWdlKGdsLkNvbnRyYWN0KToKICAgIHN0b3JhZ2U6IHN0cgoKICAgIGRlZiBfX2luaXRfXyhzZWxmLCBpbml0aWFsX3N0b3JhZ2U6IHN0cik6CiAgICAgICAgc2VsZi5zdG9yYWdlID0gaW5pdGlhbF9zdG9yYWdlCgogICAgQGdsLnB1YmxpYy52aWV3CiAgICBkZWYgZ2V0X3N0b3JhZ2Uoc2VsZikgLT4gc3RyOgogICAgICAgIHJldHVybiBzZWxmLnN0b3JhZ2UKCiAgICBAZ2wucHVibGljLndyaXRlCiAgICBkZWYgdXBkYXRlX3N0b3JhZ2Uoc2VsZiwgbmV3X3N0b3JhZ2U6IHN0cikgLT4gTm9uZToKICAgICAgICBzZWxmLnN0b3JhZ2UgPSBuZXdfc3RvcmFnZQo=",
"id": 1
}Notes:
- The
blockNumberparameter should be hex-encoded with a0xprefix - Valid
statusvalues are"decided"(default) and"finalized" - The returned code is base64-encoded
- If the contract doesn't exist at the specified block/status, an error will be returned
- If the address does not have code (not a contract), an error will be returned
- If the contract's code exceeds
node.rpc.contract_read_max_bytes, the call is refused rather than truncated, so a partial answer is never returned as a whole one
cURL Example:
# Get latest decided code
curl -X POST http://localhost:9151 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "gen_getContractCode",
"params": [{
"address": "0x73ca5a2b51edf506ceaf110a41780ec51294d89f"
}],
"id": 1
}'
# Get code at specific block with finalized status
curl -X POST http://localhost:9151 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "gen_getContractCode",
"params": [{
"address": "0x73ca5a2b51edf506ceaf110a41780ec51294d89f",
"blockNumber": "0x151ec5",
"status": "finalized"
}],
"id": 1
}'