> ## Documentation Index
> Fetch the complete documentation index at: https://docs.onebalance.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Contract Call Examples

> Explore OneBalance Toolkit contract call examples for DeFi, NFT, and payments, showing how cross-chain smart contract operations work.

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:

1. **Prepare** - Generate user operation and typed data
2. **Sign** - Sign the typed data (handled by your wallet/signer)
3. **Execute** - Submit the signed quote for execution

<Tip>
  For interactive testing, use the [API Reference playground](/api-reference/quotes/prepare-call-quote) or copy the cURL commands directly.
</Tip>

## DeFi Examples

### Uniswap V3 Swap

Swap USDC for WETH on Base using Uniswap V3 router.

<CodeGroup>
  ```json uniswap-prepare.json theme={null}
  {
    "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"
      }
    ]
  }
  ```

  ```bash prepare-uniswap-swap.sh theme={null}
  curl --request POST \
    --url https://be.onebalance.io/api/quotes/prepare-call-quote \
    --header 'Content-Type: application/json' \
    --header 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
    --data '{
    "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"
      }
    ]
  }'
  ```
</CodeGroup>

### Aave V3 Supply

Supply USDC to Aave V3 on Base to earn yield.

<CodeGroup>
  ```json aave-supply-prepare.json theme={null}
  {
    "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"
      }
    ]
  }
  ```

  ```bash prepare-aave-supply.sh theme={null}
  curl --request POST \
    --url https://be.onebalance.io/api/quotes/prepare-call-quote \
    --header 'Content-Type: application/json' \
    --header 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
    --data '{
    "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"
      }
    ]
  }'
  ```
</CodeGroup>

## NFT Examples

### Mint NFT Collection

Mint 2 NFTs from a collection on Base with ETH payment.

<CodeGroup>
  ```json nft-mint-prepare.json theme={null}
  {
    "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"
      }
    ]
  }
  ```

  ```bash prepare-nft-mint.sh theme={null}
  curl --request POST \
    --url https://be.onebalance.io/api/quotes/prepare-call-quote \
    --header 'Content-Type: application/json' \
    --header 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
    --data '{
    "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"
      }
    ]
  }'
  ```
</CodeGroup>

## Gaming Examples

### In-Game Purchase

Purchase game item #1 using USDC as payment token.

<CodeGroup>
  ```json game-purchase-prepare.json theme={null}
  {
    "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"
      }
    ]
  }
  ```

  ```bash prepare-game-purchase.sh theme={null}
  curl --request POST \
    --url https://be.onebalance.io/api/quotes/prepare-call-quote \
    --header 'Content-Type: application/json' \
    --header 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
    --data '{
    "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"
      }
    ]
  }'
  ```
</CodeGroup>

## 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.

<CodeGroup>
  ```json basic-transfer-prepare.json theme={null}
  {
    "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"
      }
    ]
  }
  ```

  ```bash prepare-basic-transfer.sh theme={null}
  curl --request POST \
    --url https://be.onebalance.io/api/quotes/prepare-call-quote \
    --header 'Content-Type: application/json' \
    --header 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
    --data '{
    "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"
      }
    ]
  }'
  ```
</CodeGroup>

## Multi-Step Operations

### Batch Token Transfers

Send tokens to multiple recipients in a single transaction.

<CodeGroup>
  ```json batch-transfer-prepare.json theme={null}
  {
    "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"
      }
    ]
  }
  ```

  ```bash prepare-batch-transfer.sh theme={null}
  curl --request POST \
    --url https://be.onebalance.io/api/quotes/prepare-call-quote \
    --header 'Content-Type: application/json' \
    --header 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
    --data '{
    "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"
      }
    ]
  }'
  ```
</CodeGroup>

## Integration Helpers

### TypeScript Helper Functions

Utility functions to simplify contract call integration.

```typescript helper-functions.ts theme={null}
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: 0n
      }]
    }),
    value: '0x0'
  };
}
```

## Production Best Practices

<CardGroup cols={2}>
  <Card title="Validation" icon="shield-check">
    Always validate addresses, amounts, and parameters before preparing quotes. Use checksummed addresses.
  </Card>

  <Card title="Error Handling" icon="triangle-alert">
    Implement proper error handling for failed preparations, rejections, and execution failures.
  </Card>

  <Card title="Gas Estimation" icon="fuel">
    OneBalance handles gas estimation, but monitor network congestion and adjust timeouts accordingly.
  </Card>

  <Card title="Testing" icon="test-tube">
    Test all operations with small amounts before production deployment.
  </Card>
</CardGroup>

<Tip>
  **Next Steps**: Learn about [troubleshooting common issues](/guides/contract-calls/troubleshooting) or explore [advanced patterns](/guides/contract-calls/advanced-patterns) for complex use cases.
</Tip>
