coinsSRC20 Workflow

Full SRC20 workflow - register viewing key, transfer, watch events

This example demonstrates a complete SRC20 token workflow including token metadata retrieval, balance queries, transfers, approvals, and event monitoring. SRC20 is Seismic's privacy-preserving token standard with shielded balances and amounts.

Prerequisites

# Install the SDK
pip install seismic-web3

# Set environment variables
export PRIVATE_KEY="your_64_char_hex_private_key"
export TOKEN_ADDRESS="0x..." # SRC20 token contract address

Basic SRC20 Token Interaction

import os
from seismic_web3 import create_wallet_client, PrivateKey, SEISMIC_TESTNET, SRC20_ABI
from hexbytes import HexBytes


def decode_uint256(raw: HexBytes) -> int:
    """Decode a uint256 from ABI-encoded bytes."""
    return int.from_bytes(raw[-32:], "big")


# Setup
private_key = PrivateKey.from_hex_str(os.environ["PRIVATE_KEY"])
w3 = SEISMIC_TESTNET.wallet_client(private_key)

# Create SRC20 token instance (SDK provides SRC20_ABI)
token_address = os.environ["TOKEN_ADDRESS"]
token = w3.seismic.contract(token_address, SRC20_ABI)

# Get token metadata (transparent reads - metadata is public)
print("Token Metadata:")
name = token.tread.name()
symbol = token.tread.symbol()
decimals_raw = token.tread.decimals()

print(f"  Name: {name.decode('utf-8') if isinstance(name, bytes) else name}")
print(f"  Symbol: {symbol.decode('utf-8') if isinstance(symbol, bytes) else symbol}")
print(f"  Decimals: {decode_uint256(decimals_raw)}")

# Get your balance (signed read - proves identity)
print("\nChecking balance...")
balance_raw = token.read.balanceOf()
balance = decode_uint256(balance_raw)
decimals = decode_uint256(decimals_raw)
print(f"  Your balance: {balance / (10 ** decimals)} tokens")
print(f"  Raw balance: {balance}")

Complete Transfer Workflow

Approval and TransferFrom Pattern

Minting Tokens (Admin Operation)

Watching Transfer Events

Async SRC20 Workflow

Batch Transfers

Error Handling

Expected Output

Common Variations

With Decimal Conversion

Check Multiple Allowances

Next Steps

See Also

Last updated