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));
Yasuo
  • 31
  • 3

2 Answers2

5

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();
Greg Scullard
  • 241
  • 1
  • 10
0

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.

Tom
  • 1
  • 1