英文:
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 是财政合约):
-
可支付的构造函数直接调用代理方法(我认为这应该是可以的,因为合约本身充当财政库,因此交易签名者应该是财政合约)。在这里,我从财政合约的构造函数直接调用 proxy.mintToken,并将 CreateContractTransaction 设置为 setInitialBalance(new HBAR(1000)) 和 setMaxTransactionFee(new Hbar(1000))。
-
使用委托调用和调用尝试从可支付的构造函数中调用代理方法(与上述相同,但使用委托调用/调用)。
-
在财政合约中有一个调用 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):
-
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)).
-
Using delegate call and call to try calling the proxy method from the payable constructor (same as above but using delegate call/call).
-
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
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论