evm_decode_revert_for

Returns a revert diagnostic using the ABI registered locally for a chain, contract, and block; use it when ABI selection depends on contract context.

Example

Local

1
WITH registered AS MATERIALIZED (
2
SELECT evm_register_contract_abi(
3
1,
4
'0x0000000000000000000000000000000000000510'::ADDRESS,
5
'[{"type":"error","name":"ERC20InsufficientBalance","inputs":[{"name":"sender","type":"address"},{"name":"balance","type":"uint256"},{"name":"needed","type":"uint256"}]}]'::JSON,
6
'OpenZeppelin ERC-20',
7
20000000,
8
20000000
9
) AS ok
10
)
11
SELECT evm_decode_revert_for(
12
1,
13
'0x0000000000000000000000000000000000000510'::ADDRESS,
14
20000000,
15
error_selector('ERC20InsufficientBalance(address,uint256,uint256)')::BYTES
16
|| evm_abi_word('0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472'::ADDRESS)::BYTES
17
|| evm_abi_word(500000000::UINT256)::BYTES
18
|| evm_abi_word(615568393::UINT256)::BYTES
19
) AS diagnostic
20
FROM registered
21
WHERE ok;
22
-- diagnostic.name = ERC20InsufficientBalance
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

evm_decode_revert_for(UBIGINT, ADDRESS, UBIGINT, BYTES) #

Looks up ABI metadata for the contract context, then decodes the revert payload.

Note: The contract ABI must already be registered.

Inputs

Name Type Use
chain_id UBIGINT

Chain id used to resolve registered ABI metadata.

required positional
address ADDRESS

Contract address used to resolve registered ABI metadata.

required positional
block_number UBIGINT

Block number for ABI registry validity range selection.

required positional
revert_data BYTES

Raw revert bytes returned by a failed call.

required positional

Returns

Name Type
diagnostic JSON

Contextual revert diagnostic JSON. Uses error_decode_json shapes; decoded custom errors add abi_label when the registration has a label.

Guidance

Decode with local contract context

The function reads only the current database's ABI registry. Validity endpoints are inclusive, and a NULL endpoint in a registration is unbounded.

  • Register the ABI before decoding. Required NULL inputs propagate NULL.
  • If no registration matches, built-in Error(string) and Panic(uint256) can still decode; other payloads return unknown with their raw selector and payload words.

Related functions

Category and tags

Tag
ABI
Tag
Evidence