gen_getContractState
Retrieves the current state of a GenLayer intelligent contract at a specific block height and transaction status.
Method: gen_getContractState
Parameters:
request(object, required): The contract state 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: Hex-encoded contract state data
Limits:
| Limit | Default | Config key |
|---|---|---|
| Contract bytes read per call | 16 MB | node.rpc.contract_read_max_bytes |
This method reads the contract's whole storage, so its cost grows with the contract. The limit stops the read once the contract exceeds it and returns an error, rather than returning part of the state as if it were all of it. Operators may reduce it; 0 or less disables it.
Example Request - Latest Decided State:
{
"jsonrpc": "2.0",
"method": "gen_getContractState",
"params": [
{
"address": "0x73ca5a2b51edf506ceaf110a41780ec51294d89f"
}
],
"id": 1
}Example Request - Specific Block and Status:
{
"jsonrpc": "2.0",
"method": "gen_getContractState",
"params": [
{
"address": "0x73ca5a2b51edf506ceaf110a41780ec51294d89f",
"blockNumber": "0x151ec5",
"status": "decided"
}
],
"id": 1
}Example Response:
{
"jsonrpc": "2.0",
"result": "0xd9960e0773746f726167656c6e757064617465642074657374207374",
"id": 1
}Notes:
- The
blockNumberparameter should be hex-encoded with a0xprefix - Valid
statusvalues are"decided"(default) and"finalized" - The returned state is hex-encoded binary data with a
0xprefix - Empty contract state returns
"0x" - If the contract doesn't exist at the specified block/status, an error will be returned
cURL Example:
# Get latest decided state
curl -X POST http://localhost:9151 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "gen_getContractState",
"params": [{
"address": "0x73ca5a2b51edf506ceaf110a41780ec51294d89f"
}],
"id": 1
}'
# Get state at specific block with decided status
curl -X POST http://localhost:9151 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "gen_getContractState",
"params": [{
"address": "0x73ca5a2b51edf506ceaf110a41780ec51294d89f",
"blockNumber": "0x151ec5",
"status": "decided"
}],
"id": 1
}'