[SOLVED] Can’t get event value from executeFunction

Hi,

I put event and emit in my function. The function run smoothly but there is no return, or event value. What do I need to do to get the return? Please see the code below.

    event mintComplete(uint256 tokenId);

    constructor() ERC721("XTALWEAPON", "XTW") {}

    function safeMint(address to, string memory uri)
        external
        onlyOwner
        returns (uint256)
    {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
        emit mintComplete(tokenId);
        return tokenId;
    }

This is the response I get:


{

* type: 2,

* chainId: 80001,

* nonce: 116,

* maxPriorityFeePerGas: {
  * type: "BigNumber",

  * hex: "0x59682f00"},

* maxFeePerGas: {
  * type: "BigNumber",

  * hex: "0x59682f12"},

* gasPrice: null,

* gasLimit: {
  * type: "BigNumber",

  * hex: "0x025f0e"},

* to: "0xA118b5f01e578337FD7cA3135493c7e73540ba24",

* value: {
  * type: "BigNumber",

  * hex: "0x00"},

* data: "0xd204c45e000000000000000000000000daee44f78f989b951e6a6cb0eec300754b8f67d10000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005068747470733a2f2f697066732e6d6f72616c69732e696f3a323035332f697066732f516d5648366d58635a454c4656436d7a386d76595668574678594368314e53685834786633744e7272777678387300000000000000000000000000000000",

* accessList: [ ],

* hash: "0xb97ba02dfe5d008ee10b146f4e5fa62644e17b87cefdd6fdcf0ba49b37229f08",

* v: 0,

* r: "0x1134e62c69a883b5171b92208eef55bfb173d32a08f07d55cb37d9223a1a530a",

* s: "0x674f7026d46b009aadd7acd3197dad10e80de86681407fce0e604cc5703a4339",

* from: "0xc4Bc0e9238aD0618AA13b1D7BF1Fd5E70AD127Dc",

* confirmations: 0

}

this seems to be the info about the transaction that you send, maybe you need to use transaction.wait() to get that info about the event after the transaction is mined on chain

Thank you for the reply. I tried to use the wait() function but it never seem to work. Can you please advise where should I put the transaction.wait()

Right now what I am trying to do is to put below:

 let result = await Moralis.executeFunction(options);
 await result.wait(1);
 console.log('wait for 1 block',result);
 return res.json(result);

What is the output for the code that you have there?

This is the return I get:


wait for 1 block {
  type: 2,
  chainId: 80001,
  nonce: 145,
  maxPriorityFeePerGas: BigNumber { _hex: '0x59682f00', _isBigNumber: true },
  maxFeePerGas: BigNumber { _hex: '0x59682f12', _isBigNumber: true },
  gasPrice: null,
  gasLimit: BigNumber { _hex: '0x025f0e', _isBigNumber: true },
  to: '0xA118b5f01e578337FD7cA3135493c7e73540ba24',
  value: BigNumber { _hex: '0x00', _isBigNumber: true },
  data: '0xd204c45e000000000000000000000000daee44f78f989b951e6a6cb0eec300754b8f67d10000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000005068747470733a2f2f697066732e6d6f72616c69732e696f3a323035332f697066732f516d5648366d58635a454c4656436d7a386d76595668574678594368314e53685834786633744e7272777678387300000000000000000000000000000000',
  accessList: [],
  hash: '0x355d55621c766d1b414ac941448fc9a2a80879bb74728d86b97f63a752996807',
  v: 0,
  r: '0x425f61a079c220915d70a0381aa1168cc50690cec7daee23935917c3a200a152',
  s: '0x4964b50e71e0b1192c7e3b8b224fee84ebac08847be374ec7d3ec4c95bc6cd74',
  from: '0xc4Bc0e9238aD0618AA13b1D7BF1Fd5E70AD127Dc',
  confirmations: 0,
  wait: [Function (anonymous)]
}

Try to get what this call returns in a variable

Thank you. I tried put in variables and get a different result now. I can see there is a mintComplete event. But I still have not find the tokenId in the event mintComplete(uint256 tokenId) that I am looking for. My code read like this.

 let result = await Moralis.executeFunction(options);
 let x=await result.wait(1);
 console.log('wait for 1 block',result,x);
 return res.json(result);

And the result looks like this:

{
  to: '0xA118b5f01e578337FD7cA3135493c7e73540ba24',
  from: '0xc4Bc0e9238aD0618AA13b1D7BF1Fd5E70AD127Dc',
  contractAddress: null,
  transactionIndex: 29,
  gasUsed: BigNumber { _hex: '0x025f0e', _isBigNumber: true },
  logsBloom: '0x00000000000000020000000000000000000002000000000000000000000000000000000000200200000000000000000000008000000001000000000000000000000000000200000000000008000000800000000000000000000100000000000020000000020000020020000000000800000000000000000080000010000000000000000000000000000000000000400000000000000000000000000000000000200000000000000022000000000000000001000000100000000000000000004000001002000000000001000000002000000000000000000000100000000020200000000000000000000000000000000008000000000000000000000000100000',
  blockHash: '0xf9c5616484dd3888c82007f67ccde277266520fa602bc51c5db6dd060ff3649e',
  transactionHash: '0x6c33adda502db48911b1cc2ba6ad64af9917a65a7a96bf6d1a2cd6d110005d3f',
  logs: [
    {
      transactionIndex: 29,
      blockNumber: 25962812,
      transactionHash: '0x6c33adda502db48911b1cc2ba6ad64af9917a65a7a96bf6d1a2cd6d110005d3f',
      address: '0xA118b5f01e578337FD7cA3135493c7e73540ba24',
      topics: [Array],
      data: '0x',
      logIndex: 98,
      blockHash: '0xf9c5616484dd3888c82007f67ccde277266520fa602bc51c5db6dd060ff3649e'
    },
    {
      transactionIndex: 29,
      blockNumber: 25962812,
      transactionHash: '0x6c33adda502db48911b1cc2ba6ad64af9917a65a7a96bf6d1a2cd6d110005d3f',
      address: '0xA118b5f01e578337FD7cA3135493c7e73540ba24',
      topics: [Array],
      data: '0x000000000000000000000000000000000000000000000000000000000000000c',
      logIndex: 99,
      blockHash: '0xf9c5616484dd3888c82007f67ccde277266520fa602bc51c5db6dd060ff3649e'
    },
    {
      transactionIndex: 29,
      blockNumber: 25962812,
      transactionHash: '0x6c33adda502db48911b1cc2ba6ad64af9917a65a7a96bf6d1a2cd6d110005d3f',
      address: '0x0000000000000000000000000000000000001010',
      topics: [Array],
      data: '0x0000000000000000000000000000000000000000000000000000d402eb23920000000000000000000000000000000000000000000000000004142fdee2b12c6e000000000000000000000000000000000000000000000b163e98f912eac466b400000000000000000000000000000000000000000000000004135bdbf78d9a6e000000000000000000000000000000000000000000000b163e99cd15d5e7f8b4',
      logIndex: 100,
      blockHash: '0xf9c5616484dd3888c82007f67ccde277266520fa602bc51c5db6dd060ff3649e'
    }
  ],
  blockNumber: 25962812,
  confirmations: 1,
  cumulativeGasUsed: BigNumber { _hex: '0x4098f6', _isBigNumber: true },
  effectiveGasPrice: BigNumber { _hex: '0x59682f09', _isBigNumber: true },
  status: 1,
  type: 2,
  byzantium: true,
  events: [
    {
      transactionIndex: 29,
      blockNumber: 25962812,
      transactionHash: '0x6c33adda502db48911b1cc2ba6ad64af9917a65a7a96bf6d1a2cd6d110005d3f',
      address: '0xA118b5f01e578337FD7cA3135493c7e73540ba24',
      topics: [Array],
      data: '0x',
      logIndex: 98,
      blockHash: '0xf9c5616484dd3888c82007f67ccde277266520fa602bc51c5db6dd060ff3649e',
      args: [Array],
      decode: [Function (anonymous)],
      event: 'Transfer',
      eventSignature: 'Transfer(address,address,uint256)',
      removeListener: [Function (anonymous)],
      getBlock: [Function (anonymous)],
      getTransaction: [Function (anonymous)],
      getTransactionReceipt: [Function (anonymous)]
    },
    {
      transactionIndex: 29,
      blockNumber: 25962812,
      transactionHash: '0x6c33adda502db48911b1cc2ba6ad64af9917a65a7a96bf6d1a2cd6d110005d3f',
      address: '0xA118b5f01e578337FD7cA3135493c7e73540ba24',
      topics: [Array],
      data: '0x000000000000000000000000000000000000000000000000000000000000000c',
      logIndex: 99,
      blockHash: '0xf9c5616484dd3888c82007f67ccde277266520fa602bc51c5db6dd060ff3649e',
      args: [Array],
      decode: [Function (anonymous)],
      event: 'mintComplete',
      eventSignature: 'mintComplete(uint256)',
      removeListener: [Function (anonymous)],
      getBlock: [Function (anonymous)],
      getTransaction: [Function (anonymous)],
      getTransactionReceipt: [Function (anonymous)]
    },
    {
      transactionIndex: 29,
      blockNumber: 25962812,
      transactionHash: '0x6c33adda502db48911b1cc2ba6ad64af9917a65a7a96bf6d1a2cd6d110005d3f',
      address: '0x0000000000000000000000000000000000001010',
      topics: [Array],
      data: '0x0000000000000000000000000000000000000000000000000000d402eb23920000000000000000000000000000000000000000000000000004142fdee2b12c6e000000000000000000000000000000000000000000000b163e98f912eac466b400000000000000000000000000000000000000000000000004135bdbf78d9a6e000000000000000000000000000000000000000000000b163e99cd15d5e7f8b4',
      logIndex: 100,
      blockHash: '0xf9c5616484dd3888c82007f67ccde277266520fa602bc51c5db6dd060ff3649e',
      removeListener: [Function (anonymous)],
      getBlock: [Function (anonymous)],
      getTransaction: [Function (anonymous)],
      getTransactionReceipt: [Function (anonymous)]
    }
  ]
}

I can see now that the event result is in the Args array. Thank you so much for your great help :slight_smile: