y-pakorn / flutter_web3

Web3 Ethereum, Etherjs and Wallet Connect wrapper for Flutter Web.
Other
134 stars 47 forks source link

return value from function transaction on chain #41

Closed URSFR closed 2 years ago

URSFR commented 2 years ago

I am trying to return a uint256 (which is a tokenId generated after minted the ERC721) value from my smart contract, but have not succeeded

Code of smart contract in Solidity

 event EquipmentMinNFTId(uint256 tokenfid);

  function EquipmentMintNFT(string memory uri)  public returns (uint256) {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(msg.sender, tokenId);
        _setTokenURI(tokenId, uri);
        emit EquipmentMinNFTId(tokenId);
        return tokenId;

    }

Later, when creating the smart contract in Solidity, I have inserted the corresponding ABI in flutter and made the references to the contract

 final anotherBusd = web3provider.Contract(
      contractAddress,
      jsonInterface,
      signer,
    );

(I use web3provider as prefix because it makes conflict with Provider package)

After the transaction is signed I have the notification that it is completed but here is the problem because I cannot return the UINT256 value of EquipmentMintNFT which I made an event called EquipmentMinNFTId from which when following the example showing how to use filters posted on this same github does not return any value nor continues executing the code after it

I tried return the uint256 through a event but it gives nothing without error

 final filter = anotherBusd.getFilter('EquipmentMinNFTId', [MetaMaskProvider.currentAddress]);
           // Fluttertoast.showToast(msg: filter.tokenId.toString());
           final res = await anotherBusd.queryFilter(filter);

the smart contract works but not the filter

I tried after receipt = tx.wait getting the logs, but it doesnt retrieve the uint256 receipt.logs

I tried wait for transaction : web3provider.provider!.waitForTransaction(receipt.transactionHash);

What am I skipping or what am I doing wrong? I need to pass the UINT256 generated at the time the function is executed and completed in the smart contract and send or collect it in flutter

Thanks

UPDATE: I got the filter to work but I still can't get the UINT

URSFR commented 2 years ago

fixed :)

princepspolycap commented 2 years ago

@URSFR Can you help me figure out how to get the balance of an account on the Gnosis Chain ?I keep getting the error that my provider is undefined or null, I created an issue here explaining more information https://github.com/y-pakorn/flutter_web3/issues/43