0

I have smart contract server function and that function including emit and event.

event TokenMinted(
        address indexed _recipient, 
        uint256 indexed _tokenId
        );

 function mintToken(address to, address[] memory bundle) public {
        // Mint new token
        uint256 tokenId = _tokenIdCounter.current();
        .........
        // Emit TokenMinted event
        emit TokenMinted(to, tokenId);
        // Increase the token counter
        _tokenIdCounter.increment();
    }

Not I'm going to call this function and hope to get tokenId.

But In my React frontend code, I can't find method to get tokenId.

export const mintToken = async (contract, to, address) => {
  let tokenId = await contract.mintToken(to, address);
  console.log('contracts', contract)
  // console.log('contract.events', contract.filters.TokenMinted())
  //get the latest blocknumber

  return tokenId;
}

The contract generated like this.

new ethers.Contract(ROCI_MINTER_ADDR, ROCI_MINTER_ABI, library.getSigner());

How can I get this value correctly? Thanks for attention.

1
  • I would recommend adding a getBalance view function which returns an array of ids that the caller owns. Then you can use this function to see if there are any changes.
    – trizin
    Sep 16 at 21:43
0

that is not neither a view or a pure function, so you probably are looking for something like this (check here for documentation):

let tx = await contract.mintToken(to, address).send({from: '0x123123123123'});

let events = tx.receipt.events
console.log(events)
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.