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

huangapple go评论57阅读模式
英文:

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

问题

我有一个关于 INSUFFICIENT_TX_FEE 错误的问题,我在以下情况下遇到了这个错误。首先,一些背景:我有一个应该充当财政库的合约。在安全模型更新之前,它会调用 HTS.createFungibleToken 并将自身设为财政库。在更新后,我将所有 HTS 函数调用移至一个 "proxy" 合约,该合约扩展了 HTS,用于关联令牌等,因为现在我们需要将从财政合约委托调用到 "proxy" 合约,以便关联代币的 EOA 的签名传播到 HTS 调用。

由于某种原因,尽管我写入调用时发送了超过 1000 HBAR,但在以下每种情况下,我都不断收到 "INSUFFICIENT_TX_FEE" 错误,这里是一些参考代码(HTSProxy 是直接调用 HTS 的代理合约,LDCREToken 是财政合约):

  1. 可支付的构造函数直接调用代理方法(我认为这应该是可以的,因为合约本身充当财政库,因此交易签名者应该是财政合约)。在这里,我从财政合约的构造函数直接调用 proxy.mintToken,并将 CreateContractTransaction 设置为 setInitialBalance(new HBAR(1000)) 和 setMaxTransactionFee(new Hbar(1000))。

  2. 使用委托调用和调用尝试从可支付的构造函数中调用代理方法(与上述相同,但使用委托调用/调用)。

  3. 在财政合约中有一个调用 proxy.mintToken 的方法,直接调用,并使用委托调用/调用(基本上尝试上述两种情况,但使用与构造函数分离的方法)。在这里,我在 ContractExecuteTransaction 上设置 setPayableAmount(new HBAR(1000)) 和 setMaxTransactionFee(new HBAR(1000))。

我认为我可以通过在部署两个合约后从 hashgraph SDK 中调用代理合约的 mintToken 来解决这个问题,并适当传递财政合约地址,但我不确定为什么我现在所做的事情不起作用。

以下是第 3 种情况的 Solidity 代码:

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

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
    );
}

答案1

得分: 0

调用Solidity中的可支付方法,你需要向智能合约发送一些Hbar以用于交易费用。因此,在调用调用HTS预编译的函数时,你需要通过调用setPayableAmount来发送一些Hbar,并指定你想发送的Hbar数量。以下是如何调用setPayableAmount的示例代码:

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

此外,请确保在调用代理智能合约时也传递价值(hbar):

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

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
    );

}

huangapple
  • 本文由 发表于 2023年4月17日 15:13:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76032517.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定