I am trying to connect EC2 with my testnet CA which I deployed on Mumbai. The Contract is a functions as an NFT, inheriting ERC721.sol from @openzeppelin. I created my Instance in aws EC2, and I wrote main.js which has info about CA & ABI I deployed on Mumbai. Then I use Postman to send GET & POST requests to call functions of CA connected to main.js. The problem I have is, after I mint simple NFT with POST request, I send GET request to get my balance(which must be +1 after I minted), but the balance of my address is still zero. I have no idea how to fix this.

These are my code below:

// function mint in myNFT.sol
function mint(
        address _to,
        string memory _name,
        string memory _url,
        string memory _attribute1
    ) public {
        // I used struct to myNFT
        uint _tokenId = myNFTs.length;
            myNFT(_name, _url, _attribute1)
        _mint(_to, _tokenId);

// the part of main.js that calls the mint function
app.post('/mint', async function(req, res) {
    const _to = req.body.to;
    const _name = req.body.name;
    const _url = req.body.url;
    const _attribute = req.body.attribute;
    try {
        const bytedata = await contract.methods.mint(_to, _name, _url, _attirubte).encodeABI();
        const mintTx = {
            from: CONTRACT_ADDRESS,
            to: _to,
            gas: 1000000,
            gasPrice: '21000000000',
            data: bytedata
        const signedTx = await web3.eth.accounts.mintTx, PRIV_KEY);
        const sentTx = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
    } catch (err) {
        res.status(500).send({ error: err.toString() });

// This is the body part of the POST request I made in postman
// requested url: my-ec2-public-ipv4:3000/mint
    "to": "0xF806711dfa8193F860EBBcEfCEa6DF0665903f16",
    "name": "name",
    "url": "123",
    "attribute": "attribute"

1 Answer 1


Two errors that I see.

  1. The line const signedTx = await web3.eth.accounts.mintTx, PRIV_KEY); looks like a typo or error. The method web3.eth.accounts.mintTx does not exist in the Web3.js library. You're probably intending to sign the transaction before sending it, which should be done with the web3.eth.accounts.signTransaction method.

  2. the to: field in your mintTx object is set to _to. This should be set to the contract address because you are calling a method (mint) on the contract, not sending Ether to _to.

  • Thank you for the answer!
    – Ljyeon
    Commented Jun 22, 2023 at 5:36

Your Answer

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

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