contract_revert_exected Hedera智能合约

发布于 2025-02-12 02:17:55 字数 1957 浏览 2 评论 0原文

Contract_revert_execuded 不确定我在做什么错,但是我正在尝试调用一个函数,并且它需要一个参数,并且我确保它是正确的,但它仍然会恢复。这是使用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));

CONTRACT_REVERT_EXECUTED
Not sure what I'm doing wrong but I'm trying to call a function and it takes in one parameter and I made sure it was correct but it still reverts. This is hedera-hashgraph using HederaTokenService.

Smart Contract:

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

Calling the transaction in js:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生活了然无味 2025-02-19 02:17:56

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

https://hashscan.io/testnet/testnet/transaction/1675427464.278782297

? message is 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b52656d697420746f6b656e20616c726561647920637265617465640000000000

with the error message starting with 0x08c379a, we know it's a string, so we can decode it

Hacky way:

  • Navigate to:
  • 粘贴上面的(删除0x)
  • 选择ASCII以编码为字符的ASCII
  • 按下转换

输出:âyy&nbsp; 创建的汇总令牌

已在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();

Also note that a REVERT does usually contain useful information, you can navigate to hashscan.io to look up the response from your smart contract, for example

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

shows a contract that reverted, the error message is 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b52656d697420746f6b656e20616c726561647920637265617465640000000000

with the error message starting with 0x08c379a, we know it's a string, so we can decode it

Hacky way:

Output: Ãy  Remit token already created

In 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();
一页 2025-02-19 02:17:56

看起来您正在尝试调用JS的Mintfungibletoken ,但智能合约没有mintfungibletoken函数;智能合约功能名称为mintnonfungibletoken

It looks like you're trying to call mintFungibleToken from JS, but the smart contract doesn't have a mintFungibleToken function; the smart contract function name is mintNonFungibleToken.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文