Loading

call

Scalar function

Invokes eth_call using the provided transport, target address, and calldata, returning the raw bytes.

call(TRANSPORT, ADDRESS, BLOB)

Parameters

Name Type
transport TRANSPORT
to ADDRESS
data BLOB

Returns

Name Type
result BLOB
1
-- Check the WETH balance of Vitalik's address via balanceOf
2
WITH transport AS (
3
SELECT http_transport('https://mainnet.optimism.io') AS transport
4
),
5
abi AS (
6
SELECT '[
7
{
8
"type": "function",
9
"name": "balanceOf",
10
"stateMutability": "view",
11
"inputs": [{ "name": "account", "type": "address" }],
12
"outputs": [{ "type": "uint256" }]
13
}
14
]'::JSON AS abi_json
15
),
16
calldata AS (
17
SELECT encode_function_data(abi.abi_json, 'balanceOf', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'::ADDRESS) AS data
18
FROM abi
19
)
20
SELECT call(transport.transport,
21
'0x4200000000000000000000000000000000000006'::ADDRESS,
22
calldata.data)::UINT256 AS balance
23
FROM transport, calldata;
Notebook ready in readonly mode.

call(TRANSPORT, ADDRESS, BLOB, BIGINT)

Adds an explicit block height (or alias like 'latest') for deterministic historical calls.

Parameters

Name Type
transport TRANSPORT
to ADDRESS
data BLOB
block_number BIGINT

Returns

Name Type
result BLOB
1
-- Pin Vitalik's balance check to block 36,760,640
2
WITH transport AS (
3
SELECT http_transport('https://mainnet.optimism.io') AS transport
4
),
5
abi AS (
6
SELECT '[
7
{
8
"type": "function",
9
"name": "balanceOf",
10
"stateMutability": "view",
11
"inputs": [{ "name": "account", "type": "address" }],
12
"outputs": [{ "type": "uint256" }]
13
}
14
]'::JSON AS abi_json
15
),
16
calldata AS (
17
SELECT encode_function_data(abi.abi_json, 'balanceOf', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'::ADDRESS) AS data
18
FROM abi
19
)
20
SELECT call(transport.transport,
21
'0x4200000000000000000000000000000000000006'::ADDRESS,
22
calldata.data,
23
36760640)::UINT256 AS balance
24
FROM transport, calldata;
Notebook ready in readonly mode.