Skip to main content
Ralph contracts on Alephium expose two ways to read data contract state (raw field values stored on-chain) and view functions (computed results from calling a read-only function). This guide covers both.

Get contract state

Returns the raw storage fields of a deployed contract. No transaction needed this is a direct state read.
immFields are set at deployment and never change. mutFields change as the contract executes transactions. Field order matches the order they are declared in the Ralph source code.

Field types

Call a view function

View functions run contract code without broadcasting a transaction. Use this to get computed values token balances, prices, ownership checks anything the contract calculates rather than stores directly.
methodIndex is the zero-based index of the function in the contract. If the contract has three public functions, they are 0, 1, and 2 in declaration order.

Call a view function with arguments

Pass arguments in the args array using the same type names as the field types above:

Call multiple functions in one request

Use multicall-contract to batch several calls into a single round trip:
Results are returned in the same order as the calls array.

Get contract bytecode

Returns the compiled bytecode of a contract by its code hash. Useful for verifying a deployed contract matches a known build:

Get parent and sub-contracts

Ralph supports hierarchical contract relationships. A factory contract can deploy child contracts you can navigate that tree: Get the parent of a contract:
Get sub-contracts deployed by a contract:
Get the total sub-contract count:

Read contract events

Events emitted by a contract are queryable by contract address. Use start and limit to paginate:
eventIndex maps to the order events are declared in the Ralph contract. nextStart is the offset to pass to fetch the next page store it between requests rather than calculating it yourself.

Get the current event count

Before paginating events, check how many exist so you can page backwards from the latest:
To fetch the most recent 20 events set start to count - 20.

Parameters reference

Next steps

Contract events

Subscribe to and query events from Ralph contracts

Error handling

Retry logic and error code reference