hand-holding-dollarToken Interaction

Reading and writing SRC20 token balances and allowances

Read shielded balances and write shielded state changes on SRC20 tokens using seismic-alloy.

Overview

SRC20 token interaction in Rust follows the same builder pattern as all seismic-alloy contract calls:

  • Transparent reads (metadata) -- Use provider.call() without .seismic()

  • Signed reads (balances, allowances) -- Use provider.seismic_call() with .seismic()

  • Shielded writes (transfers, approvals) -- Use provider.send_transaction() with .seismic()

Defining the Interface

use alloy::sol;

sol! {
    interface ISRC20 {
        function name() public view returns (string);
        function symbol() public view returns (string);
        function decimals() public view returns (uint8);
        function totalSupply() public view returns (uint256);

        function balanceOf(address account) public view returns (suint256);
        function transfer(address to, suint256 amount) public returns (bool);
        function approve(address spender, suint256 amount) public returns (bool);
        function allowance(address owner, address spender) public view returns (suint256);
        function transferFrom(address from, address to, suint256 amount) public returns (bool);

        event Transfer(address indexed from, address indexed to, suint256 value);
        event Approval(address indexed owner, address indexed spender, suint256 value);
    }
}

Reading Token Metadata

Token metadata (name, symbol, decimals, totalSupply) is not shielded. Use a plain transparent read:

circle-info

Metadata reads do not require a wallet or signed provider. An unsigned provider works fine since these values are not shielded.

Reading Shielded Balances

balanceOf() is a shielded read. The contract uses msg.sender to authenticate the caller, so you must use seismic_call() (a signed read) on a SeismicSignedProvider.

circle-exclamation

Reading Allowances

Allowance reads may also be shielded depending on the contract implementation. Use a signed read to be safe:

Shielded Writes

Transfer Tokens

Send tokens using a shielded write. The transfer amount is encrypted in calldata:

Approve a Spender

Operation Summary

Operation
Method
Builder
Provider Required

Read name/symbol/decimals

provider.call()

No .seismic()

Any provider

Read balanceOf

provider.seismic_call()

.seismic()

SeismicSignedProvider

Read allowance

provider.seismic_call()

.seismic()

SeismicSignedProvider

Transfer tokens

provider.send_transaction()

.seismic()

SeismicSignedProvider

Approve spender

provider.send_transaction()

.seismic()

SeismicSignedProvider

Notes

  • All shielded operations require a SeismicSignedProvider with a wallet

  • The .seismic() builder method marks the transaction for calldata encryption

  • The filler pipeline automatically handles encryption nonce, TEE pubkey, and AES-GCM encryption

  • Shielded types (suint256) appear as their standard counterparts (uint256) in the ABI encoding

See Also

Last updated