0

I am trying to build a Ethereum NFT minting website where the website users can mint NFTs on blockchain without an external wallet (e.g. Metamask). I asked a question here before and got reply as to how to achieve this. How to use one Ethereum account for all NFT minting transactions for website users

The advice given was that the user can use the hdwallet provider and the Ethers.js library. This way, the minting fees can be paid from a central Ethereum account.

Now, I have coded the application as follows. The minting works and the transaction is recorded on the Rinkerby test network.

    import LocationNFT from '../abis/Location.json'
    let nftAddress = "0x....";
    let privateKey= "0x....";
    let provider = ethers.getDefaultProvider('rinkeby');
    let wallet = new ethers.Wallet(privateKey, provider);
    var mainContract = new ethers.Contract(nftAddress, LocationNFT.abi, wallet); 
    const num = mainContract.mintNFT(location).send({ from: fromAddress })  
      .once('receipt', (receipt) => 
      {
             console.log ('num: ', num);
             console.log ('JSON.stringify(num) : ', JSON.stringify(num));
               
      }) 

Location Contract code: Contains only the following function:

    function mintNFT(string memory _location) public returns (uint256) {    
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();    
        require(!_locationExists[_location]);
        uint _id = locations.push(_location);
        _mint(msg.sender, _id);
        _locationExists[_location] = true;
        return newItemId;
    }

However, regardless of the successful minting on the Rinkerby test network, I do get the following error which is shown in the console. I would like to resolve this so that I get can get the transaction number ('num' in the above code) which I can show to the user.

Could anyone help me resolve this error?

    TypeError: mainContract.mintNFT(...).send is not a function
     at App._this.mint (App.js:359)
     at onSubmit (App.js:475)
     at HTMLUnknownElement.callCallback (react-dom.development.js:147)
     at Object.invokeGuardedCallbackDev (react-dom.development.js:196)
     at invokeGuardedCallback (react-dom.development.js:250)
     at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:265)
     at executeDispatch (react-dom.development.js:571)
     at executeDispatchesInOrder (react-dom.development.js:596)
     at executeDispatchesAndRelease (react-dom.development.js:695)
     at executeDispatchesAndReleaseTopLevel (react-dom.development.js:704)
     at forEachAccumulated (react-dom.development.js:676)
     at runEventsInBatch (react-dom.development.js:844)
     at runExtractedEventsInBatch (react-dom.development.js:852)
     at handleTopLevel (react-dom.development.js:5030)
     at batchedUpdates$1 (react-dom.development.js:21425)
     at batchedUpdates (react-dom.development.js:2247)
     at dispatchEvent (react-dom.development.js:5110)
     at react-dom.development.js:21482
     at Object.unstable_runWithPriority (scheduler.development.js:255)
     at interactiveUpdates$1 (react-dom.development.js:21481)
     at interactiveUpdates (react-dom.development.js:2268)
     at dispatchInteractiveEvent (react-dom.development.js:5086)
5
  • It seems you are using etherjs which uses a different syntax than web3js. It should be await mainContract.mintNFT(location). The other problem in your example is that transactions do not return a value, see ethereum.stackexchange.com/questions/765/… for the details.
    – Ismael
    Nov 11, 2021 at 3:57
  • I still want to mint the NFT using an address (fromaddress). That is why I need that part added. Nov 11, 2021 at 22:58
  • The syntaxis in etherjs is different. Check their documentation for the differences docs.ethers.io/v5/migration/web3. I think in your case you need to use a signer. If you don't want to learn the syntax probably it will be easier to switch to web3js instead.
    – Ismael
    Nov 12, 2021 at 4:08
  • Hi, its absolute necessary that I use Ethers.js and not web3 as I am using a hdwallet instead of metamask. please see why I need this requirement from the linked post in my question. Nov 13, 2021 at 15:15
  • I put a link to etherjs documentation on how to migrate from web3. In any case you could use hdwallet with web3. Both work well just use whatever is good for you.
    – Ismael
    Nov 14, 2021 at 4:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.