In our previous guides, we covered how to receive stablecoin payments, implement AML Compliance checks, and swap supported assets through Blockradar’s APIs. These are the essential building blocks for most fintechs. However, this guide moves beyond the basics.
It’s now time to move to the “advanced” section where you can unlock the full potential of onchain finance. You might ask yourself, “what if I need to go beyond what’s natively supported in Blockradar? What if I want to interact with a protocol, my own token, or onchain service that’s unique to my business?”
That’s where Custom Smart Contracts come in. This advanced feature lets you interact with any smart contract directly from your Blockradar wallet without managing RPC endpoints, signing flows, or contract deployments yourself.
That means you can:
- Connect to DeFi protocols for yield or liquidity management.
- Automate stablecoin lending, staking, or treasury operations within your fintech stack.
- Integrate tokenized real-world assets (RWAs) into your product flows.
- Power programmable settlements, payouts, or compliance checks using onchain logic.
- Extend your platform with your own custom tokens, reward systems, or fee rules executed securely onchain.
In short, if it’s onchain, you can now do it from within Blockradar. All you need is the Custom Smart Contract API, which allows you to:
- Read data from any smart contract.
- Write to (execute) any smart contract function.
- Estimate gas/network fees before execution.
In this example, we’ll:
- Check the token balance using contracts/read.
- Approve Uniswap to spend that token.
- Estimate the network fee for swapping that token into USDT using Uniswap’s smart contract.
- Execute the swap with contracts/write.
- Confirm success via webhook events.
Step 1: Understand the Swap Contract
We’ll use Uniswap’s V2 Router contract and its swapExactTokensForTokens method.
Method signature:
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
- amountIn – The amount of the unsupported token you want to sell.
- amountOutMin – The minimum stablecoin you’re willing to accept (protects against slippage).
- path – The token addresses for the swap route.
- to – Your Blockradar wallet address (receiver of the stablecoin).
- deadline – Unix timestamp after which the transaction fails.
Step 2: Read the Token Balance
Before swapping, you’ll want to check how much of the token your wallet holds.
Endpoint:
POST /v1/wallets/{walletId}/contracts/read
Example:
const url = 'https://api.blockradar.co/v1/wallets/{walletId}/contracts/read';
const options = {
method: 'POST',
headers: {
'x-api-key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
abi: [{
"constant": true,
"inputs": [{"name": "_owner", "type": "address"}],
"name": "balanceOf",
"outputs": [{"name": "balance", "type": "uint256"}],
"payable": false,
"stateMutability": "view",
"type": "function"
}],
address: "0xUnsupportedTokenAddress",
method: "balanceOf",
parameters: ["0xYourWalletAddress"]
})
};
const res = await fetch(url, options);
const data = await res.json();
console.log(data);
/*
{
"data": "1000000000000000000", // balance in smallest unit
"message": "Contract read successfully"
}
*/
- abi – The ABI (Application Binary Interface) of the contract function you’re calling. In this case, balanceOf(address).
- address – The address of the token’s smart contract.
- method – The name of the method to call (e.g., balanceOf).
- parameters – The arguments for that method (here: your wallet address).
💡 Use this step to determine amountIn for the swap call.
Step 3: Approve Uniswap to Spend the Token
Before swapping, you must grant Uniswap Router permission to move your token. This is done with the token contract’s approve function.
Endpoint:
POST /v1/wallets/{walletId}/contracts/writeExample:
const url = "https://api.blockradar.co/v1/wallets/{walletId}/contracts/write";
const options = {
method: "POST",
headers: { "x-api-key": "<api-key>", "Content-Type": "application/json" },
body: JSON.stringify({
abi: [
{
constant: false,
inputs: [
{ name: "_spender", type: "address" },
{ name: "_value", type: "uint256" },
],
name: "approve",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
],
address: "0xUnsupportedTokenAddress",
method: "approve",
parameters: ["0xUniswapRouterAddress", "1000000000000000000"], // approve 1 token
}),
};🔔 Important: Don’t move to the swap immediately.
Wait for Blockradar’s custom-smart-contract.success webhook to confirm that the approval transaction was mined successfully. Only then proceed to Step 4.
Example webhook payload:
{
"event": "custom-smart-contract.success",
"data": {
"status": "SUCCESS",
"type": "CUSTOM_SMART_CONTRACT",
"hash": "0xfedcba098765...",
"tokenAddress": "0xUnsupportedTokenAddress",
......
}
}Step 4: Estimate the Network Fee
Before executing a swap, you can estimate the gas cost.
Endpoint:
POST /v1/wallets/{walletId}/contracts/network-feeExample:
const url =
"https://api.blockradar.co/v1/wallets/{walletId}/contracts/network-fee";
const options = {
method: "POST",
headers: {
"x-api-key": "<api-key>",
"Content-Type": "application/json",
},
body: JSON.stringify({
abi: [
/* ABI of swapExactTokensForTokens */
],
address: "0xUniswapRouterAddress",
method: "swapExactTokensForTokens",
parameters: [
"1000000000000000000", // amountIn from balanceOf
"990000", // amountOutMin
["0xUnsupportedTokenAddress", "0xUSDTAddress"], // path
"0xYourWalletAddress",
Math.floor(Date.now() / 1000) + 60 * 20, // deadline
],
}),
};
const res = await fetch(url, options);
const data = await res.json();
console.log(data);
// {
// "data": {
// "balance": "1.0123", // native token balance
// "fee": "0.00422" // estimated network fee
// }
// }
Parameter Breakdown
- abi – The ABI for the function you want to call (here: Uniswap swap).
- address – The contract address for Uniswap’s router.
- method – The function name (swapExactTokensForTokens).
- parameters – All arguments to pass to that function, matching ABI order.
Step 5: Execute the Swap
Once you know the balance and fee, you can execute the swap.
Endpoint:
POST /v1/wallets/{walletId}/contracts/writeExample:
const url = 'https://api.blockradar.co/v1/wallets/{walletId}/contracts/write';
const options = {
method: 'POST',
headers: {
'x-api-key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
abi: [ /* ABI of swapExactTokensForTokens */ ],
address: "0xUniswapRouterAddress",
method: "swapExactTokensForTokens",
parameters: [
"1000000000000000000", // amountIn
"990000", // amountOutMin
["0xUnsupportedTokenAddress", "0xUSDTAddress"],
"0xYourWalletAddress",
Math.floor(Date.now() / 1000) + 60 * 20
]
})
};
const res = await fetch(url, options);
const data = await res.json();
console.log(data);
/*
{
"message": "Contract write initiated successfully",
"data": {
"status": "PENDING",
"type": "CUSTOM_SMART_CONTRACT"
}
}
*/You would get another custom-smart-contract.success webhook to confirm that the execution is successful.
Example webhook payload:
{
"event": "custom-smart-contract.success",
"data": {
"status": "SUCCESS",
"type": "CUSTOM_SMART_CONTRACT",
"hash": "0xfedcba098765...",
"tokenAddress": "0xUniswapRouterAddress",
.......
}
}Parameter Breakdown
- All other parameters are the same as in the fee estimation step.
Other Smart Contract Endpoints
- contracts/write/sign – Signs a transaction without broadcasting it. Use if another service or custodian needs to submit the transaction.
- contracts/read – As shown above, for fetching contract state before execution.
Security & Compliance
Even when calling an arbitrary smart contract:
- The transaction still comes from your Blockradar wallet.
- Native AML/compliance checks apply where possible.
Why This Is Important
With Custom Smart Contracts, Blockradar evolves from a non-custodial wallet infrastructure into a programmable execution layer for fintech developers.
You can now interact with any smart contract via API, whether it’s a DeFi protocol, staking or lending pool, tokenized asset (RWA) platform, or a custom stablecoin contract, while still using the same secure wallets, compliance rules, and monitoring built into Blockradar.
Each transaction is signed, broadcast, and verified through Blockradar’s infrastructure, eliminating the need to manage RPC endpoints, node operations, gas estimation, or private key handling manually.
For engineers building payments, treasury, or onchain automation, this means one API surface for everything:
- Wallet management
- AML/KYT
- Swaps
- Settlements
- Custom smart contract interactions
Blockradar makes it possible to build, automate, and scale advanced onchain financial operations securely and programmatically.
About Blockradar
Blockradar provides secure, developer-friendly stablecoin infrastructure for fintechs. Our non-custodial wallet APIs, transaction monitoring, and AML compliance tools make it easy to launch and scale stablecoin-powered financial services. From USDC and USDT payouts to onchain expense management, we help companies move money instantly and safely across borders—without building blockchain infrastructure in-house.
Blockradar is trusted by payment platforms, remittance providers, and Web3 startups building the future of finance.
Explore our API documentation and get started at https://blockradar.co

