Yas*_*suo 2 solidity hashgraph hedera-hashgraph
CONTRACT_REVERT_EXECUTED
不知道我做错了什么,但我正在尝试调用一个函数,它接受一个参数,我确保它是正确的,但它仍然会恢复。这是使用 HederaTokenService 的 hedera-hashgraph。
智能合约:
pragma solidity ^0.8.11;
import "./hip-206/HederaTokenService.sol";
import "./hip-206/HederaResponseCodes.sol";
contract Minting is HederaTokenService {
address tokenAddress;
bytes metadata;
string baseURI = "abc";
uint64 mintPrice;
function mintNonFungibleToken(uint64 _amount) external payable {
bytes[] memory nftMetadatas = generateBytesArrayForHTS(
baseURI,
_amount
);
(
int256 response,
uint64 newTotalSupply,
) = HederaTokenService.mintToken(tokenAddress, _amount, metadata);
if (response != HederaResponseCodes.SUCCESS) {
revert("Mint Failed");
}
}
// @dev Helper function which generates array of addresses required for HTSPrecompiled
function generateAddressArrayForHTS(address _address, uint256 _items)
internal
pure
returns (address[] memory _addresses)
{
_addresses = new address[](_items);
for (uint256 i = 0; i < _items; i++) {
_addresses[i] = _address;
}
}
// @dev Helper function which generates array required for metadata by HTSPrecompiled
function generateBytesArrayForHTS(bytes memory _bytes, uint256 _items)
internal
pure
returns (bytes[] memory _bytesArray)
{
_bytesArray = new bytes[](_items);
for (uint256 i = 0; i < _items; i++) {
_bytesArray[i] = _bytes;
}
}
Run Code Online (Sandbox Code Playgroud)
在js中调用事务:
const contractMint = await new ContractExecuteTransaction()
.setContractId(contractId)
.setGas(3000000)
.setFunction(
"mintFungibleToken",
new ContractFunctionParameters().addUint64(1)
)
.setMaxTransactionFee(new Hbar(2));
Run Code Online (Sandbox Code Playgroud)
小智 5
另请注意,REVERT 通常包含有用的信息,例如,您可以导航到 hashscan.io 以查找智能合约的响应
\nhttps://hashscan.io/testnet/transaction/1675427464.278782297?tid=0.0.1189-1675427451-309271560
\n显示已恢复的合约,错误消息是0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b52656d697420746f6b656e20616c726561647920637265617465640000000000
错误消息以 开头0x08c379a,我们知道它是一个字符串,因此我们可以对其进行解码
哈克方式:
\n输出:\xc3\x83y\xc2\xa0 汇款令牌已创建
\n在 JavaScript 中
\nconst {ethers} = require("ethers");\n\nasync function main() {\n\n const error = "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b52656d697420746f6b656e20616c726561647920637265617465640000000000";\n const reason = ethers.utils.defaultAbiCoder.decode(\n [\'string\'],\n ethers.utils.hexDataSlice(error, 4)\n )\n console.log(reason);\n};\n\nvoid main();\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
653 次 |
| 最近记录: |