Search code examples
blockchainsolidityhedera-hashgraphhashgraph

I am getting an INSUFFICIENT_TX_FEE error when trying to call a Solidity function that mints an HTS token


I have a question regarding an INSUFFICIENT_TX_FEE error that I am getting for the following cases. First, some background: I have a contract that is supposed to act as a treasury. Prior to the security model updates, it would call HTS.createFungibleToken and set itself as the treasury. Following the updates, I moved all HTS function calls to a "proxy" contract that extended HTS for things such as associating tokens, as we now need to delegate call from the treasury contract to the "proxy" contract so that the EOA that is associating the token has their signature propagated to the HTS call.

For some reason, I keep getting the INSUFFICIENT_TX_FEE error on Token Create in each of the following cases, despite writing the calls to send over 1000 HBAR with it. Here is some code for reference in the images (HTSProxy is the proxy contract directly calling HTS, LDCREToken is the treasury contract):

  1. Payable constructor directly calling the proxy method (I thought this would be okay without delegate call since the contract itself is acting as the treasury, so it would make sense for the transaction signer to be the treasury contract). Here, I do proxy.mintToken directly from the treasury contract's constructor, and I set the CreateContractTransaction to have setInitialBalance(new HBAR(1000)) and setMaxTransactionFee(new Hbar(1000)).

  2. Using delegate call and call to try calling the proxy method from the payable constructor (same as above but using delegate call/call).

  3. Having a method on the treasury contract that calls proxy.mintToken directly and with delegate call/call (basically trying the two above but with a method separate from the constructor). Here, I set setPayableAmount(new HBAR(1000)) and setMaxTransactionFee(new HBAR(1000)) on the ContractExecuteTransaction.

I think I may be able to get around this by calling the proxy contract's mintToken from the hashgraph SDK after deploying both contracts and passing the treasury contract address appropriately, but I am not sure why what I am doing now wouldn't work.

The following is the Solidty code for case 3

function mintToken() external payable {
    (int responseCode, address _tokenAddress) = htsProxy.mintToken(
        "OraCRE",
        "OraCRE",
        address(this),
        1000000000,
        8
    );
}

Solution

  • To call a payable method in Solidity, you have to send some Hbar to the smart contract to be used for the transaction fee. Therefore, when calling a function that calls an HTS precompile, you have to send some Hbar by calling setPayableAmount and specifying the amount of Hbar you want to send along. An example code of how you can call setPayableAmount is as follows:

    const transaction = new ContractExecuteTransaction()
            .setGas(2700000)
            .setPayableAmount(100)
            .setContractId(contractId)
            .setFunctionParameters(functionParameters)
            .setMaxTransactionFee(100);
    

    Also, make sure that you also pass the value (hbar) to the proxy smart contract when you call it like.

    function mintToken() external payable {
        (int responseCode, address _tokenAddress) = htsProxy.mintToken{value: msg.value}(
            "OraCRE",
            "OraCRE",
            address(this),
            1000000000,
            8
        );
    

    }