Skip to main content

Interaction with Smart Contracts

Interacting with a smart contract involves calling read or write methods on a specific contract. These functions can range from simple standard ERC-20 methods to complex smart contract logic invocations. Fireblocks offers several ways to interact with smart contracts:
  1. Interact with a Deployed Smart Contract via the Fireblocks Console - Learn more here.
  2. Use the Fireblocks EVM Web3 Provider or Local JSON RPC Tools.
  3. Use the Fireblocks REST API.

Using the Web3 Provider and Local JSON RPC Tools

These tools allow you to seamlessly integrate Fireblocks into your codebase.

EVM Web3 Provider

The EVM Web3 Provider is an EIP1193 compatible provider that can be integrated into your EVM client library (such as ethers, web3, viem) with a simple configuration. For more details, see the Web3 Provider developer guide.

Local JSON RPC

Local JSON RPC provides the same functionality as the Web3 provider but is designed for customers who do not use JavaScript-based tools for their smart contract development and integration. For more details, see the Local JSON RPC developer guide.

Using the Fireblocks REST API

Direct interaction with smart contracts via the Fireblocks API can be achieved by calling the Create Transaction API endpoint. To perform a contract call, set the operation parameter to CONTRACT_CALL and include the contractCallData parameter in the extraParams object of the POST request body. The contractCallData value should be the hex-encoded data you want to pass to the contract. This can be structured using well-known libraries such as web3.js, ethers.js, or similar. For more details, see the Create Transactions Developer Guide.

Interpret contract call results with networkRecords

A single CONTRACT_CALL transaction can move several assets on-chain (for example, a DeFi swap or withdrawal that returns multiple tokens). The top-level assetId, amount, and netAmount fields on the transaction response describe only the outer call, and are commonly 0 when no native asset was sent. To see the actual asset movements produced by the contract, read the networkRecords array. Each NetworkRecord entry describes one intermediate blockchain transfer that Fireblocks aggregated under the parent transaction, with fields including assetId, netAmount, source, destination, destinationAddress, txHash, and status. To classify movements from the perspective of one of your vault accounts:
  • Sent asset: entries where source.id equals your vault account ID.
  • Received asset: entries where destination.id equals your vault account ID.
  • Skip zero-value noise: entries where netAmount is "0".
networkRecords is populated after the transaction is broadcast and Fireblocks has parsed the receipt, so it may be empty on early transaction statuses. Wait for a terminal status (for example, COMPLETED) before relying on it. For simple TRANSFER operations, the top-level assetId and amount are sufficient and networkRecords is empty.

Approve Amount Cap

In the ERC20 standard, the approve operation is a crucial function that allows a token owner to authorize another address (usually a smart contract) to spend a specified amount of tokens on their behalf. This function is commonly used in DeFi applications, token swaps, and other scenarios where tokens need to be managed by smart contracts.

How It Works

When you call the approve function, you specify two parameters:
  • spender: The address that will be allowed to spend the tokens.
  • amount: The maximum number of tokens that the spender is allowed to spend.
The approve function updates the allowance, which is the amount of tokens that the spender can use. This is recorded in the token contract’s internal mapping.

Example Use Case

Suppose you want to use a DeFi platform to lend your tokens. You would first call the approve function to allow the platform’s smart contract to transfer tokens from your address. Once approved, the platform can transfer the specified amount of tokens from your address to the lending pool. The Amount Cap limits the amount smart contracts and third-party dApps may withdraw on your behalf. This reduces the risk associated with granting an unlimited approval amount. Transaction amounts are then automatically changed from the maximum amount to the user-specified limit for all Approve transactions created with dApps. Learn more about limiting the Amount Cap for Approve transactions via the Fireblocks Console.