How to I interact smart contract through Firblocks

Is there a way to interact with the smart contract? As add addreses to a contract, executing a contract etc? I cant find it in the API reference. (it has only basic topic like “create a contract”, “find specific contract”, etc)

@yogevh
The first option is to use the Create Transaction endpoint and use make sure the operation is CONTRACT_CALL. That is, assuming you have already built a contract transaction using web3py, web3js or etherJS. You can find a few examples for this here:

You can also review the Ethereum Development article for interacting with Smart contracts, or the Ethereum Smart Contract Development article for deploying new contracts.

2 Likes

Is there any example of how to send a smart contract transaction (to trigger an api inside?) I couldn’t find any in the above.

Hi @yogevh, here’s an example:

fireblocksApiClient.createTransaction({
    operation: TransactionOperation.CONTRACT_CALL,
    assetId: "ETH",
    source: {
        type: PeerType.VAULT_ACCOUNT,
        id: "0" /* Source Vault Account ID */
    },
    destination: {
        type: PeerType.CONTRACT,
        id: /*externalWalletId here*/
    },
    note: "Contract Call Transaction",
    amount: "0",
    extraParameters: {
        contractCallData: "0x38ed17390000000000000000000000000000000000000000000000000000000bb6c179cc" /* Data Payload */
    }
});

The assetId indicates that I want to call a contract on Ethereum.
The source object indicates that I want to call the contract from my Ethereum address in vault 0.
The destination object indicates that I want to call a whitelisted contract address.
You can pass value via the amount field.
And the payload is passed in extraParameters.contractCallData.

Hi Yogev,

You can also use our web3 provider with web3.js or ethers.js libraries…
An example of such usage with web3.js can be found below:

const { FireblocksWeb3Provider, ChainId } = require("@fireblocks/fireblocks-web3-provider")
const Web3 = require("web3");

const eip1193Provider = new FireblocksWeb3Provider({
    privateKey: "<your_private_key_file_path>",
    apiKey: "<your_api_key>",
    vaultAccountIds: "<vault_account_id/s>",
    chainId: ChainId.GOERLI,
});

(async() => {
    const web3 = new Web3(eip1193Provider);
    const myAddress = await web3.eth.getAccounts()
    const nonce = await web3.eth.getTransactionCount(myAddress[0], 'latest');

    const transaction = {
        'to': 'some_dest_address',
        'value': 101,
        'from': myAddress[0],
        'gas': 30000,
        'maxFeePerGas': 1000000108,
        'nonce': nonce,
       };
    
    const tx = await web3.eth.sendTransaction(transaction, myAddress[0], "")
    console.log(tx)
})();
1 Like