Direct On-Chain Contract Flow
Bind your agent wallet to MpcFirewall on NEAR so policy rules are enforced by the blockchain itself—even if the agent runtime is compromised.
1. Lock Down Agent Keys
In NEAR Chain Signatures, wallets are derived from the caller's account name. Bind your treasury to the firewall contract account (mpc-firewall.testnet), then give your agent a restricted key that can only call MpcFirewall entrypoints.
// 1. Give your AI agent a NEAR key that ONLY calls MpcFirewall
// (never grant direct access to v1.signer-prod.testnet).
near contract add-function-call-key <agent>.testnet <agent-pubkey> \
contract mpc-firewall.testnet \
method-names verify_and_sign_evm,verify_and_sign_btc,verify_and_sign_btc_bip143 \
allowance 1.0 NEAR
// 2. Whitelist that agent inside your MpcFirewall policy (Owner or DAO only).
near contract call-function as-transaction mpc-firewall.testnet add_authorized_agent \
json-args '{ "agent": "<agent>.testnet" }' \
prepaid-gas '30.0 Tgas' attached-deposit '0 NEAR' sign-as <owner>.testnet2. Sign EVM Transactions
Serialize the unsigned EIP-1559 (or Legacy/EIP-2930) transaction using a fresh EVM nonce and unique tx_id, then pass the hex string on-chain.
import { ethers } from 'ethers';
// Build the full unsigned EIP-1559 transaction (do NOT hash it yourself)
const erc20 = new ethers.Interface(['function transfer(address to, uint256 amount)']);
const unsignedTx = ethers.Transaction.from({
type: 2,
chainId: 8453, // Base
nonce: Math.floor(Date.now() / 1000),
maxPriorityFeePerGas: 1_000_000n,
maxFeePerGas: 25_000_000n,
gasLimit: 65_000n,
to: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // Base USDC
value: 0n,
data: erc20.encodeFunctionData('transfer', ['0x1111111111111111111111111111111111111111', 25_000_000n])
});
// Send raw unsigned bytes to MpcFirewall; the contract verifies everything,
// computes the hash on-chain, and requests a signature from v1.signer-prod.testnet.
await agentNearAccount.functionCall({
contractId: 'mpc-firewall.testnet',
methodName: 'verify_and_sign_evm',
args: {
raw_unsigned_tx_hex: unsignedTx.unsignedSerialized,
tx_id: `agent-${crypto.randomUUID()}`
},
gas: 300_000_000_000_000n,
attachedDeposit: 1n
});3. Sign Bitcoin SegWit (BIP-143)
For P2WPKH inputs, attach bip143 input metadata so the contract computes the exact Bitcoin SegWit sighash digest on-chain after verifying output scripts and satoshi caps.
await agentNearAccount.functionCall({
contractId: 'mpc-firewall.testnet',
methodName: 'verify_and_sign_btc_bip143',
args: {
raw_unsigned_btc_hex: rawBtcHex,
tx_id: `btc-${crypto.randomUUID()}`,
bip143: {
input_index: 0,
prevout_value_sats: 300000,
script_code_hex: '00141111111111111111111111111111111111111111'
}
},
gas: 300_000_000_000_000n,
attachedDeposit: 1n
});Failure Rollback & Team Voting
Every signature request registers on_mpc_sign_complete. If v1.signer fails or runs out of gas, daily token/ETH/BTC accumulators automatically revert. Medium spends above auto-approve limits park in PendingDaoApproval until dao_approve_escalated(tx_id) executes after a SputnikDAO vote.