0

We have been trying to connect the UI with the smart contract in order to carry out a mint functionality of a nft. But have been facing this error (Transaction error. Exception thrown in contract code) again and again in the function. Our mint function has 4 params (string, int, int, int) and this is the code snippet:

contractInvoiceNFT.methods.mint("url", 10, 1230, 12).send({ from: accounts, gas: 100000 }).then(function (result) {
                    console.log("test--mint");
                });

This is the whole snippet of the web3 connection part:

<script>
async function apply() {
        var web3;
        var abivalue;
        $.getJSON("/Artifacts/NFT.json", function (result) {
            console.log(result.abi);
            abivalue = result.abi;
            console.log("abi value: " + abivalue);
            var contactAddress = "0x652e2b34C5820E1444E4F3069e02a8268c38D74B";
            try {
                web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
            } catch (error) {
                alert(error)
            }
            const contractInvoiceNFT = new web3.eth.Contract(
                abivalue,
                contactAddress
            );
            console.log("contract initialization");
            const accounts = "0x94c6fC1a2e4e52FE1410392c1e3BB991FAb0cCAf";

 window.ethereum.request({ method: 'eth_requestAccounts' });
            const metamask = "0x94c6fC1a2e4e52FE1410392c1e3BB991FAb0cCAf";
            ethereum.request({
                method: 'eth_sendTransaction',
                params: [{
                    from: accounts,
                    to: "0x6C2bF1924434E463f1ac5d013e157738a953F134",
                    value: "1"

                }
                ]
            })
                .then(result)
            {
                console.log("test");
                contractInvoiceNFT.methods.mint("url", 10, 1230, 12).send({ from: accounts, gas: 100000 }).then(function (result) {
                    console.log("test--mint");
                });

            }

        })
    }
</script>

This is the error: Transaction error. Exception thrown in contract code.

Not able to figure it out.. pls do help.

The mint function:

function mint(
   
string memory _tokenURI,
uint256 _Amount,
uint256 _Value,
uint256 _duration

) public returns (uint256) {
   
   // Incrementing total supply
   
    _tokenIds.increment();
    
    uint256 _tokenId = _tokenIds.current();
   
   _mint(msg.sender, _tokenId);               // mint

   _setTokenURI(_tokenId, _tokenURI);         // setting tokenURI
   
  
   uint256 duration = block.timestamp + (_duration * 1 days);
   
   
   Metadata(msg.sender,_tokenURI,_tokenId,_Value,_Amount,duration);
   
    
   return _tokenId;                         // tokenId of an nft 

}
3
  • Please share the content of relevant solidity code (ie mint()) Nov 25 at 10:54
  • Can you paste your mint function here? To double check the params are correct Also, you can add .catch(( error => { console.log (error)} to see more
    – user86512
    Nov 25 at 20:25
  • Have added the mint function, pls do check..
    – prajwal
    Nov 29 at 4:46

Your Answer

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

Browse other questions tagged or ask your own question.