Executing a transaction
To demonstrate MagicSpend++, we’ll walk through a simple, real-world EVM transaction: transferring 1.0 USDC on Polygon. This compact example shows the full flow end-to-end—constructing ERC‑20 transfer calldata from the USDC ABI, requesting a canonical userOp hash from the backend, signing that hash with a Turnkey-backed account, producing EIP‑7702 authorization(s), and finally submitting everything to a submit endpoint.
By following this sequence, you’ll see how MagicSpend++ enables chain abstracted execution with minimal friction while keeping the signer experience familiar.
Step 1 — Build ERC‑20 Transfer Transaction Calldata
import { erc20Abi, encodeFunctionData, parseUnits } from 'viem';
const chainId = 137;
const usdc = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174';
const recipient = '0x1111111111111111111111111111111111111111';
// 1. Convert 1.0 USDC to base units (6 decimals)
const amount = parseUnits('1.0', 6);
// 2. Encode transfer(to, amount) calldata
const encodedData = encodeFunctionData({
abi: erc20Abi,
functionName: 'transfer',
args: [recipient, amount],
});import { Interface, parseUnits } from 'ethers';
const chainId = 137;
const usdc = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174';
const recipient = '0x1111111111111111111111111111111111111111';
const erc20 = new Interface([
'function transfer(address to, uint256 amount) returns (bool)'
]);
const amount = parseUnits('1.0', 6); // 1 USDC -> 1_000_000
const encodedData = erc20.encodeFunctionData('transfer', [recipient, amount]);Step 2 — Build the chain abstracted transaction (with quote type + token addresses)
Supported Settlement Tokens
USDC
USDC
Ethereum Mainnet, Arbitrum, Base, Optimism, Polygon, Avalanche, Unichain, Binance Smart Chain, World Chain, Solana
SOL
SOL
Solana
ETH
ETH
Ethereum Mainnet, Arbitrum, Base, Optimism, Polygon, Unichain, World Chain
Step 3 - Initialize turnkey and sign the user operation and authorizations
Step 4 — Sign EIP‑7702 authorization(s)
Step 5 - Submitting the transaction
Step 6 - Checking the status of the transaction
Status Codes
PENDING
Transaction is built but signatures for the transaction have not been submitted yet
SUBMITTED
Transaction has been submitted and the user's desired action will be executed on the target chain
TARGET_EXECUTED
Target chain transaction has been succeefully executed. Settlement of the transaction is now pending.
SETTLING
Settlement transactions on each of the settlement chains have been submitted and pending execution
SETTLEMENT_EXECUTED
Settlement transactions on all settlement chains have been executed
EXPIRED
Transaction was built but was not submitted on time for valid execution
FAILED
Transaction execution failed. This may be due to a reverted transaction on the target or settlement chains.
Last updated