• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

network – Issue Interacting with ERC721 Contract via Node.js Backend (Error: “missing argument” when calling mintCard), cant mint cards

Moussa by Moussa
October 20, 2024
in Bitcoin
0
peer discovery – how to obtain the IP addresses of nodes for mining pools?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


I’m working on a project to interact with an ERC721 contract through a Node.js backend using ethers.js. The contract allows minting collectible cards (NFTs). Here’s an overview of my setup:
Main.sol file:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
    
    contract Main is ERC721, Ownable {
        uint256 public nextTokenId;
        mapping(uint256 => string) private _tokenURIs;
    
        constructor() ERC721("PokemonNFT", "PKMN") {
            nextTokenId = 1;
        }
    
        function mintCard(uint256 collectionId, address to, string memory tokenURI) public onlyOwner {
            uint256 tokenId = nextTokenId;
            _safeMint(to, tokenId);
            _setTokenURI(tokenId, tokenURI);
            nextTokenId += 1;
        }
    
        function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
            require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
            return _tokenURIs[tokenId];
        }
    
        function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal {
            require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
            _tokenURIs[tokenId] = _tokenURI;
        }
    }

Node.js Script (index.js):

require('dotenv').config();
const express = require('express');
const { ethers } = require('ethers');
const app = express();
const port = 3000;

// Contract information
const CONTRACT_ADDRESS = 'contract address'; 
const ABI = [
    {
        "inputs": [],
        "stateMutability": "nonpayable",
        "type": "constructor"
    },
    {
        "inputs": [
            {
                "internalType": "uint256",
                "name": "collectionId",
                "type": "uint256"
            },
            {
                "internalType": "address",
                "name": "walletAddress",
                "type": "address"
            },
            {
                "internalType": "string",
                "name": "tokenURI",
                "type": "string"
            }
        ],
        "name": "mintCard",
        "outputs": [],
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "inputs": [
            {
                "internalType": "uint256",
                "name": "tokenId",
                "type": "uint256"
            }
        ],
        "name": "tokenURI",
        "outputs": [
            {
                "internalType": "string",
                "name": "",
                "type": "string"
            }
        ],
        "stateMutability": "view",
        "type": "function"
    }
];

// Set up provider and signer
const provider = new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545');
const walletPrivateKey = 'walletkey'; 
const signer = new ethers.Wallet(walletPrivateKey, provider); // Create signer
const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, signer); // Connect contract to signer

// Minting API endpoint
app.get('/mint/:collectionId/:walletAddress/:tokenURI', async (req, res) => {
    const { collectionId, walletAddress, tokenURI } = req.params;

    try {
        const tx = await contract.mintCard(collectionId, walletAddress, tokenURI);
        await tx.wait(); // Wait for the transaction to be confirmed
        res.status(200).json({ success: true, transactionHash: tx.hash });
    } catch (error) {
        console.error(error);
        res.status(500).json({ success: false, message: error.message });
    }
});

// API endpoint to get token information
app.get('/nft/:tokenId', async (req, res) => {
    const tokenId = req.params.tokenId; // Get tokenId from the request parameters
    try {
        const tokenURI = await contract.tokenURI(tokenId); // Call tokenURI function
        res.json({ tokenId, tokenURI }); // Respond with tokenId and tokenURI
    } catch (error) {
        res.status(400).json({ error: 'Token not found' }); // Handle error if token is not found
    }
});

// Start the server
app.listen(port, () => {
    console.log(`Server is running at http://localhost:${port}`);
});

Problem:
When I try to call the /mint endpoint with this URL:
http://localhost:3000/mint/1/0xYourWalletAddressHere/https://metadata-url

I receive an error saying :

node index.js     
Server is running at http://localhost:3000
 Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"reason":"Error: Transaction reverted: function selector was not recognized and there's no fallback function","code":"UNPREDICTABLE_GAS_LIMIT","method":"estimateGas","transaction":{"from":"Mywalletaddress","maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"maxFeePerGas":{"type":"BigNumber","hex":"0xc1b71080"},"to":"contractaddress","data":"0xf2afa53c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b8d4736382c43a4ea117af8f57ed95823d42c6c0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000003b68747470733a2f2f74636772657075626c69632e636f6d2f6d656469612f62696e6172792f3030302f3530302f3233382f3530303233382e6a70670000000000","type":2,"accessList":null},"error":{"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"id\":49,\"error\":{\"code\":-32603,\"message\":\"Error: Transaction reverted: function selector was not recognized and there's no fallback function\",\"data\":{\"message\":\"Error: Transaction reverted: function selector was not recognized and there's no fallback function\",\"data\":\"0x\"}}}","error":{"code":-32603,"data":{"message":"Error: Transaction reverted: function selector was not recognized and there's no fallback function","data":"0x"}},"requestBody":"{\"method\":\"eth_estimateGas\",\"params\":[{\"type\":\"0x2\",\"maxFeePerGas\":\"0xc1b71080\",\"maxPriorityFeePerGas\":\"0x59682f00\",\"from\":\"walletaddress\",\"to\":\"contreactaddress\",\"data\":\"0xf2afa53c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b8d4736382c43a4ea117af8f57ed95823d42c6c0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000003b68747470733a2f2f74636772657075626c69632e636f6d2f6d656469612f62696e6172792f3030302f3530302f3233382f3530303233382e6a70670000000000\"}],\"id\":49,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"http://127.0.0.1:8545"}}, tx={"data":"0xf2afa53c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b8d4736382c43a4ea117af8f57ed95823d42c6c0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000003b68747470733a2f2f74636772657075626c69632e636f6d2f6d656469612f62696e6172792f3030302f3530302f3233382f3530303233382e6a70670000000000","to":{},"from":"0x7b8D4736382c43A4eA117AF8F57eD95823d42c6C","type":2,"maxFeePerGas":{"type":"BigNumber","hex":"0xc1b71080"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"nonce":{},"gasLimit":{},"chainId":{}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.7.0)
    at Logger.makeError (/home/kali/collectible-card-game-daar/node_modules/@ethersproject/logger/lib/index.js:238:21)
    at Logger.throwError (/home/kali/collectible-card-game-daar/node_modules/@ethersproject/logger/lib/index.js:247:20)
    at /home/kali/collectible-card-game-daar/node_modules/@ethersproject/abstract-signer/lib/index.js:365:47
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Promise.all (index 7) {
  reason: 'cannot estimate gas; transaction may fail or may require manual gas limit',
  code: 'UNPREDICTABLE_GAS_LIMIT',
  error: Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="Error: Transaction reverted: function selector was not recognized and there's no fallback function", method="estimateGas", transaction={"from":"walletadress","maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"maxFeePerGas":{"type":"BigNumber","hex":"0xc1b71080"},"to":"contractaddress","data":"0xf2afa53c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b8

I also have a deployement script that contain this code”└─$

cat 000001-deploy-game.ts 
import 'dotenv/config'
import { DeployFunction } from 'hardhat-deploy/types'

const deployer: DeployFunction = async hre => {
  if (hre.network.config.chainId !== 31337) return
  const { deployer } = await hre.getNamedAccounts()
  await hre.deployments.deploy('Main', { from: deployer, log: true })
}

export default deployer

and an artifcat? json script with”

──(kali㉿kali)-[~/collectible-card-game-daar/contracts/deployments/localhost]
└─$ cat Main.json            
{
  "address": "contractaddress",
  "abi": [
    {
      "inputs": [],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "inputs": [
        {
          "internalType": "string",
          "name": "name",
          "type": "string"
        },
        {
          "internalType": "int256",
          "name": "cardCount",
          "type": "int256"
        }
      ],
      "name": "createCollection",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    }
  ],
  "transactionHash": "0xcd0a1ec8b116b46b2f3c16f8148fc567ab98e37d9a438b700574d80136d95c79",
  "receipt": {
    "to": null,
    "from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
    "contractAddress": "contractaddress",
    "transactionIndex": 0,
    "gasUsed": "706710",

”
and another main.json with: ┌──(kali㉿kali)-[~/…/contracts/artifacts/src/Main.sol]
└─$ cat Main.json

{
  "_format": "hh-sol-artifact-1",
  "contractName": "Main",
  "sourceName": "src/Main.sol",
  "abi": [
    {
      "inputs": [],
      "stateMutability": "nonpayable",
      "type": "constructor"
    },
    {
      "inputs": [
        {
          "internalType": "string",
          "name": "name",
          "type": "string"
        },
        {
          "internalType": "int256",
          "name": "cardCount",
          "type": "int256"
        }
      ],
      "name": "createCollection",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    }
  ],

I’m not sure what i’m doing wrong i’m totally new to this and I need help, thanks.



Source link

Related articles

SEC Reviews Cboe Bid to List 3x Bitcoin and Ether ETFs

SEC Reviews Cboe Bid to List 3x Bitcoin and Ether ETFs

August 16, 2026
Binance Ends Transactions With 16 Platforms, Warns of Wallet Reviews

Binance Ends Transactions With 16 Platforms, Warns of Wallet Reviews

August 16, 2026
Share76Tweet47

Related Posts

SEC Reviews Cboe Bid to List 3x Bitcoin and Ether ETFs

SEC Reviews Cboe Bid to List 3x Bitcoin and Ether ETFs

by Moussa
August 16, 2026
0

Key TakeawaysCboe asked the SEC to approve the listing of six funds that triple daily price moves.The funds would primarily...

Binance Ends Transactions With 16 Platforms, Warns of Wallet Reviews

Binance Ends Transactions With 16 Platforms, Warns of Wallet Reviews

by Moussa
August 16, 2026
0

Key TakeawaysBinance restrictions cover 16 platforms across three effective dates.Attempted transfers may trigger reviews and wallet restrictions.U.S. and U.K. sanctions...

CLARITY Act Odds Crash to 10% Before Senate Returns: Galaxy

CLARITY Act Odds Crash to 10% Before Senate Returns: Galaxy

by Moussa
August 16, 2026
0

Key TakeawaysGalaxy cut the CLARITY Act’s passage odds to 10% from 75%.A Senate cloture motion on the bill ripens at...

Ripple Confirms 75+ Speakers for Swell 2026, Expects 1,500+ Attendees

Ripple Confirms 75+ Speakers for Swell 2026, Expects 1,500+ Attendees

by Moussa
August 15, 2026
0

Key TakeawaysRipple expects more than 1,500 attendees and over 75 speakers.Robinhood, BNY, and ICE executives have joined the conference.Swell and...

How should one try verifying to whom a given Bitcoin address belongs?

by Moussa
August 15, 2026
0

Lets say, I'd have a website that shows a large number of Bitcoin public addresses, and wanted to give option...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSUzQ2RpdiUyMGNsYXNzJTNEJTIydG5wJTIwdG5wLXN1YnNjcmlwdGlvbiUyMiUzRSUwQSUzQ2Zvcm0lMjBtZXRob2QlM0QlMjJwb3N0JTIyJTIwYWN0aW9uJTNEJTIyaHR0cHMlM0ElMkYlMkZhcHByb3gub3JnJTJGJTNGbmElM0RzJTIyJTNFJTBBJTBBJTN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IwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News