shield-halvedShielded Write Complete

Full shielded write workflow from setup to confirmation

This example demonstrates a complete shielded write workflow including contract setup, encrypted transaction submission, receipt verification, and advanced patterns like custom security parameters.

Prerequisites

# Install the SDK
pip install seismic-web3

# Set environment variables
export PRIVATE_KEY="your_64_char_hex_private_key"
export CONTRACT_ADDRESS="0x..." # Your deployed contract address

Basic Shielded Write

A shielded write encrypts the transaction calldata so external observers cannot see what function you're calling or what arguments you're passing.

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

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

# Contract ABI (simplified example)
ABI = [
    {
        "name": "setNumber",
        "type": "function",
        "inputs": [{"name": "value", "type": "uint256"}],
        "outputs": [],
    },
    {
        "name": "getNumber",
        "type": "function",
        "inputs": [],
        "outputs": [{"name": "", "type": "uint256"}],
    },
]

# Create contract instance
contract_address = os.environ["CONTRACT_ADDRESS"]
contract = w3.seismic.contract(contract_address, ABI)

# Execute shielded write
print("Sending shielded transaction...")
tx_hash = contract.write.setNumber(42)
print(f"Transaction hash: {tx_hash.hex()}")

# Wait for confirmation
print("Waiting for confirmation...")
receipt = w3.eth.wait_for_transaction_receipt(tx_hash, timeout=60)

# Verify success
if receipt["status"] == 1:
    print(f"Transaction successful!")
    print(f"Block number: {receipt['blockNumber']}")
    print(f"Gas used: {receipt['gasUsed']}")
    print(f"Transaction type: 0x{receipt['type']:02x}")
else:
    print("Transaction failed!")
    raise RuntimeError(f"Transaction reverted: {tx_hash.hex()}")

Complete Workflow with Verification

Custom Security Parameters

Shielded transactions include freshness checks and expiry windows. You can customize these parameters:

Low-Level Shielded Write

For advanced use cases like contract deployment or pre-encoded calldata:

Debug Mode

Debug mode returns additional information including plaintext and encrypted data:

Error Handling

Batch Operations

Expected Output

Common Variations

With Value Transfer

Gas Estimation

Next Steps

See Also

Last updated