gpt4 book ai didi

solidity - CONTRACT_REVERT_EXECUTED Hedera 智能合约

转载 作者:行者123 更新时间:2023-12-03 08:04:36 30 4
gpt4 key购买 nike

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

在js中调用事务:

  const contractMint = await new ContractExecuteTransaction()
.setContractId(contractId)
.setGas(3000000)
.setFunction(
"mintFungibleToken",
new ContractFunctionParameters().addUint64(1)
)
.setMaxTransactionFee(new Hbar(2));

最佳答案

另请注意,REVERT 通常包含有用的信息,例如,您可以导航到 hashscan.io 以查找智能合约的响应

https://hashscan.io/testnet/transaction/1675427464.278782297?tid=0.0.1189-1675427451-309271560

显示已恢复的合约,错误消息为0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000 0000000000000000000000000000000001b52656d697420746f6b656e20616c726561647920637265617465640000000000

错误消息以0x08c379a开头,我们知道它是一个字符串,因此我们可以对其进行解码

黑客方式:

输出: ày  已创建汇款 token

在 JavaScript 中

const {ethers} = require("ethers");

async function main() {

const error = "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b52656d697420746f6b656e20616c726561647920637265617465640000000000";
const reason = ethers.utils.defaultAbiCoder.decode(
['string'],
ethers.utils.hexDataSlice(error, 4)
)
console.log(reason);
};

void main();

关于solidity - CONTRACT_REVERT_EXECUTED Hedera 智能合约,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72830889/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com