Real-world examples of smart contract calls using OneBalance APIs. Each example shows the complete flow from preparing quotes to execution with actual API payloads.
Overview
These examples demonstrate the three-step flow for contract calls:
Prepare - Generate user operation and typed data
Sign - Sign the typed data (handled by your wallet/signer)
Execute - Submit the signed quote for execution
DeFi Examples
Uniswap V3 Swap
Swap USDC for WETH on Base using Uniswap V3 router.
uniswap-prepare.json
prepare-uniswap-swap.sh
{
"account" : {
"sessionAddress" : "0x1cBFbFd62a276BF6D79d504eA4CA75a7baDcf5b1" ,
"adminAddress" : "0xc162a3cE45ad151eeCd0a5532D6E489D034aB3B8" ,
"accountAddress" : "0xE20295ec513DEf805D9c3083b0C8EaB64692D764"
},
"targetChain" : "eip155:8453" ,
"calls" : [
{
"to" : "0x2626664c2603336E57B271c5C0b26F421741e481" ,
"data" : "0x414bf389000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda029130000000000000000000000004200000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000e20295ec513def805d9c3083b0c8eab64692d764000000000000000000000000000000000000000000000000000000006748d28800000000000000000000000000000000000000000000000000000000000f42400000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000" ,
"value" : "0x0"
}
],
"allowanceRequirements" : [
{
"assetType" : "eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"amount" : "1000000" ,
"spender" : "0x2626664c2603336E57B271c5C0b26F421741e481"
}
],
"tokensRequired" : [
{
"assetType" : "eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"amount" : "1000000"
}
]
}
Aave V3 Supply
Supply USDC to Aave V3 on Base to earn yield.
aave-supply-prepare.json
prepare-aave-supply.sh
{
"account" : {
"sessionAddress" : "0x1cBFbFd62a276BF6D79d504eA4CA75a7baDcf5b1" ,
"adminAddress" : "0xc162a3cE45ad151eeCd0a5532D6E489D034aB3B8" ,
"accountAddress" : "0xE20295ec513DEf805D9c3083b0C8EaB64692D764"
},
"targetChain" : "eip155:8453" ,
"calls" : [
{
"to" : "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5" ,
"data" : "0x617ba037000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000098968000000000000000000000000e20295ec513def805d9c3083b0c8eab64692d7640000000000000000000000000000000000000000000000000000000000000000" ,
"value" : "0x0"
}
],
"allowanceRequirements" : [
{
"assetType" : "eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"amount" : "10000000" ,
"spender" : "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5"
}
],
"tokensRequired" : [
{
"assetType" : "eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"amount" : "10000000"
}
]
}
NFT Examples
Mint NFT Collection
Mint 2 NFTs from a collection on Base with ETH payment.
nft-mint-prepare.json
prepare-nft-mint.sh
{
"account" : {
"sessionAddress" : "0x1cBFbFd62a276BF6D79d504eA4CA75a7baDcf5b1" ,
"adminAddress" : "0xc162a3cE45ad151eeCd0a5532D6E489D034aB3B8" ,
"accountAddress" : "0xE20295ec513DEf805D9c3083b0C8EaB64692D764"
},
"targetChain" : "eip155:8453" ,
"calls" : [
{
"to" : "0x1234567890123456789012345678901234567890" ,
"data" : "0xa0712d680000000000000000000000000000000000000000000000000000000000000002" ,
"value" : "0x1bc16d674ec80000"
}
],
"allowanceRequirements" : [],
"tokensRequired" : [
{
"assetType" : "eip155:8453/slip44:60" ,
"amount" : "2000000000000000000"
}
]
}
Gaming Examples
In-Game Purchase
Purchase game item #1 using USDC as payment token.
game-purchase-prepare.json
prepare-game-purchase.sh
{
"account" : {
"sessionAddress" : "0x1cBFbFd62a276BF6D79d504eA4CA75a7baDcf5b1" ,
"adminAddress" : "0xc162a3cE45ad151eeCd0a5532D6E489D034aB3B8" ,
"accountAddress" : "0xE20295ec513DEf805D9c3083b0C8EaB64692D764"
},
"targetChain" : "eip155:8453" ,
"calls" : [
{
"to" : "0x1234567890123456789012345678901234567890" ,
"data" : "0x96a81f59000000000000000000000000000000000000000000000000000000000000000100000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000098968" ,
"value" : "0x0"
}
],
"allowanceRequirements" : [
{
"assetType" : "eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"amount" : "10000000" ,
"spender" : "0x1234567890123456789012345678901234567890"
}
],
"tokensRequired" : [
{
"assetType" : "eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"amount" : "10000000"
}
]
}
Basic Account Examples
Basic accounts use a simpler structure with just signer and account addresses.
Token Transfer with Basic Account
Transfer USDC tokens using a basic account configuration.
basic-transfer-prepare.json
prepare-basic-transfer.sh
{
"account" : {
"type" : "kernel-v3.1-ecdsa" ,
"signerAddress" : "0x5d6fb4eb211a6a2e406a1111b54d26c534753c8e" ,
"accountAddress" : "0xb7bc0d7baf6761c302ff6772dfd8f9e22ec706e7"
},
"targetChain" : "eip155:8453" ,
"calls" : [
{
"to" : "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"data" : "0xa9059cbb000000000000000000000000742d35cc6634c0532925a3b844bc454e4438f44e0000000000000000000000000000000000000000000000000000000000989680" ,
"value" : "0x0"
}
],
"allowanceRequirements" : [],
"tokensRequired" : [
{
"assetType" : "eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"amount" : "10000000"
}
]
}
Multi-Step Operations
Batch Token Transfers
Send tokens to multiple recipients in a single transaction.
batch-transfer-prepare.json
prepare-batch-transfer.sh
{
"account" : {
"sessionAddress" : "0x1cBFbFd62a276BF6D79d504eA4CA75a7baDcf5b1" ,
"adminAddress" : "0xc162a3cE45ad151eeCd0a5532D6E489D034aB3B8" ,
"accountAddress" : "0xE20295ec513DEf805D9c3083b0C8EaB64692D764"
},
"targetChain" : "eip155:8453" ,
"calls" : [
{
"to" : "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"data" : "0xa9059cbb000000000000000000000000742d35cc6634c0532925a3b844bc454e4438f44e0000000000000000000000000000000000000000000000000000000000989680" ,
"value" : "0x0"
},
{
"to" : "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"data" : "0xa9059cbb000000000000000000000000456d35cc6634c0532925a3b844bc454e4438f44e0000000000000000000000000000000000000000000000000000000000989680" ,
"value" : "0x0"
},
{
"to" : "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"data" : "0xa9059cbb000000000000000000000000789d35cc6634c0532925a3b844bc454e4438f44e0000000000000000000000000000000000000000000000000000000000989680" ,
"value" : "0x0"
}
],
"allowanceRequirements" : [],
"tokensRequired" : [
{
"assetType" : "eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" ,
"amount" : "30000000"
}
]
}
Integration Helpers
TypeScript Helper Functions
Utility functions to simplify contract call integration.
import { encodeFunctionData , parseAbi } from 'viem' ;
// Generate transfer call data
export function createTransferCall (
tokenAddress : string ,
recipient : string ,
amount : bigint
) {
return {
to: tokenAddress ,
data: encodeFunctionData ({
abi: parseAbi ([ 'function transfer(address to, uint256 amount)' ]),
functionName: 'transfer' ,
args: [ recipient , amount ]
}),
value: '0x0'
};
}
// Generate approve call data
export function createApprovalRequirement (
tokenAddress : string ,
spender : string ,
amount : bigint ,
chainId : number
) {
return {
assetType: `eip155: ${ chainId } /erc20: ${ tokenAddress } ` ,
amount: amount . toString (),
spender
};
}
// Generate Uniswap V3 swap call data
export function createUniswapV3Swap (
tokenIn : string ,
tokenOut : string ,
fee : number ,
recipient : string ,
amountIn : bigint ,
amountOutMinimum : bigint ,
deadline : number
) {
const swapRouter = '0x2626664c2603336E57B271c5C0b26F421741e481' ;
return {
to: swapRouter ,
data: encodeFunctionData ({
abi: parseAbi ([
'function exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160)) returns (uint256)'
]),
functionName: 'exactInputSingle' ,
args: [{
tokenIn ,
tokenOut ,
fee ,
recipient ,
deadline ,
amountIn ,
amountOutMinimum ,
sqrtPriceLimitX96: 0 n
}]
}),
value: '0x0'
};
}
Production Best Practices
Validation Always validate addresses, amounts, and parameters before preparing quotes. Use checksummed addresses.
Error Handling Implement proper error handling for failed preparations, rejections, and execution failures.
Gas Estimation OneBalance handles gas estimation, but monitor network congestion and adjust timeouts accordingly.
Testing Test all operations with small amounts on testnet before production deployment.