Interact With Smart Contracts
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:
- Interact with a Deployed Smart Contract via the Fireblocks Console - Learn more here.
- Use the Fireblocks EVM Web3 Provider or Local JSON RPC Tools.
- 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.
Learn more about the Web3 Provider in the following 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.
Learn more about the Local JSON RPC in the following 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.
Check out the Create Transactions Developer Guide.
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.
Updated 6 months ago