Note
You can also whitelist a smart contract address in the Fireblocks Console. Learn more about whitelisting addresses.
Overview
Fireblocks Smart Contract API allows you to initiate special transactions that interact directly with any smart contract deployed on an Ethereum Virtual Machine (EVM) compatible network. This allows you to run contract operations not natively supported on the Fireblocks API, such as Decentralized Finance (DeFi) transactions and Non-Fungible Token (NFT) transfers.
Creating a smart contract transaction on EVM-compatible blockchains
If you already use libraries such as Web3.js or Ethers.js, you can bridge between these libraries and the Fireblocks API using the Fireblocks Web3 Provider and Hardhat Plugin.
Alternatively, you can call the Create a new transaction endpoint directly with the following parameters:
- Operation: Set to CONTRACT_CALL.
- Source: The vault account ID from which the transaction is initiated.
- Destination: The transaction destination should point to the smart contract you want to call. This can be either a whitelisted address or a one-time address.
- Asset: The asset type should always be the base asset of the relevant EVM-compatible blockchain.
- Amount (optional): You can pass a positive amount if you want to transfer the base asset to the contract. By default, this is zero.
- Data Payload: Pass the data payload as the ContractCallData field under extraParameters.
The example below is a Javascript code sample of a smart contract call:
fireblocksApiClient.createTransaction({
operation: TransactionOperation.CONTRACT_CALL,
assetId: "ETH",
source: {
type: PeerType.VAULT_ACCOUNT,
id: "0" /* Source Vault Account ID */
},
destination: {
type: PeerType.EXTERNAL_WALLET,
id: externalWalletId
},
note: "Contract Call Transaction",
amount: "0",
extraParameters: {
contractCallData: "0x38ed17390000000000000000000000000000000000000000000000000000000bb6c179cc" /* Data Payload */
}
});
Calculating the data payload
The data payload encapsulates the contract method to call its parameters using a special encoding method known as ABI. To generate the data payload, you can use ABI encoding libraries such as EthereumJS ABI or libraries that allow interaction with Ethereum contracts, such as Web3.js or Ethers.js.
Contract deployment
You can use the Fireblocks API to deploy smart contracts onto any EVM-compatible blockchain. To do so, use the same CONTRACT_CALL format as above but with the following parameters:
-
Destination: The transaction destination should be a null one-time address:
"0x0"
. -
Destination ID: The destination ID needs to be set to
null
orremoved
. -
Destination Type: The destination type needs to be set to
PeerType.ONE_TIME_ADDRESS
. - Data Payload: Enter the encoded contract data you want to deploy.
fireblocksApiClient.createTransaction({
operation: TransactionOperation.CONTRACT_CALL,
assetId: "ETH",
source: {
type: PeerType.VAULT_ACCOUNT,
id: "0" /* Source Vault Account ID */
},
destination: {
type: PeerType.ONE_TIME_ADDRESS,
oneTimeAddress: {
id: "0x0"
}
},
note: "Contract Call Transaction",
amount: "0",
extraParameters: {
contractCallData: "<Deployment Transaction Payload>" /* Data Payload */
}
});
Managing NFTs with Fireblocks
The Fireblocks Web3 Provider and Hardhat Plugin also include the ability to interact with NFTs.
You can:
- Natively connect to base tokens in the ERC-721 and ERC-1155 formats.
- Connect to custom tokens by specifying your own ABI (Application Binary Interface) addresses.
- Seamlessly use methods from the Fireblocks API to interact with your wallet and transfers.
For examples of interacting with NFT contracts in Javascript, see our GitHub repository.
Setting TAP rules for contract calls
Learn more about using TAP for DeFi operations on Fireblocks.