Record provenance actions on-chain usingcreateViemAdapter(server-side) orcreateEIP1193Adapter(browser wallets). Both implementIChainAdapter.
IChainAdapter Interface
createViemAdapter
For server-side or Node.js environments.ViemAdapterOptions
| Option | Type | Description |
|---|---|---|
walletClient | WalletClient | viem wallet client with account set |
publicClient | PublicClient | viem public client for simulation + receipts |
contractAddress | 0x${string} | Deployed ProvenanceRegistry address |
createEIP1193Adapter
For browser environments with any EIP-1193 wallet.EIP1193AdapterOptions
| Option | Type | Description |
|---|---|---|
provider | EIP1193Provider | Any EIP-1193 compatible provider |
contractAddress | string | Deployed ProvenanceRegistry address |
chainId | number | Chain ID (used in ext:onchain@1.0.0) |
chainName | string | Human-readable chain name |
from | string | Optional: override sender address (e.g. smart wallet) |
eth_callto simulaterecordActionAndRegisterOutputs→ getactionIdbytes32eth_sendTransactionto broadcast with the same calldata
Using the Adapter with ProvenanceKit
Pass the adapter aschain when constructing ProvenanceKit:
On-Chain Recording Semantics
On-chain recording is fire-and-forget:- If the chain transaction succeeds →
result.onchainis populated - If it fails (gas, RPC error, etc.) →
result.onchainisundefined; the off-chain IPFS record still succeeds
result.onchain to know if on-chain recording succeeded.
Custom IChainAdapter
ImplementIChainAdapter directly for ethers.js or any other signing library:
Smart Wallet Session Keys (No Per-Action Popups)
For the best UX in browser apps: use Privy or Coinbase Smart Wallet session keys. The user approves the session once; all subsequent provenance calls are signed silently.Gotchas
fromaddress: The EIP-1193 adapter useseth_accounts[0]as default sender. Override withfromwhen using a smart wallet that differs from the EOA signer.- Chain switching: The adapter does not switch chains automatically. Ensure the provider is on the correct chain before calling
pk.file(). - Simulation first:
createViemAdaptersimulates before broadcasting (publicClient.simulateContract). If simulation fails, no gas is spent. - EIP-1193 and
eth_call: The self-contained encoder encodes function calls without external ABI libraries. The function selector forrecordActionAndRegisterOutputsis0xd57e4f08.