community – Challenge Interacting with ERC721 Contract by way of Node.js Backend (Error: “lacking argument” when calling mintCard), cant mint playing cards – CoinNewsTrend

community – Challenge Interacting with ERC721 Contract by way of Node.js Backend (Error: “lacking argument” when calling mintCard), cant mint playing cards

[ad_1]

I am engaged on a venture to work together with an ERC721 contract by a Node.js backend utilizing ethers.js. The contract permits minting collectible playing cards (NFTs). Right here’s an outline of my setup:
Primary.sol file:

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

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/entry/Ownable.sol";
    
    contract Primary is ERC721, Ownable 
        uint256 public nextTokenId;
        mapping(uint256 => string) non-public _tokenURIs;
    
        constructor() ERC721("PokemonNFT", "PKMN") 
            nextTokenId = 1;
        
    
        perform mintCard(uint256 collectionId, deal with to, string reminiscence tokenURI) public onlyOwner 
            uint256 tokenId = nextTokenId;
            _safeMint(to, tokenId);
            _setTokenURI(tokenId, tokenURI);
            nextTokenId += 1;
        
    
        perform tokenURI(uint256 tokenId) public view digital override returns (string reminiscence) 
            require(_exists(tokenId), "ERC721Metadata: URI question for nonexistent token");
            return _tokenURIs[tokenId];
        
    
        perform _setTokenURI(uint256 tokenId, string reminiscence _tokenURI) inner 
            require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
            _tokenURIs[tokenId] = _tokenURI;
        
    

Node.js Script (index.js):

require('dotenv').config();
const categorical = require('categorical');
const  ethers  = require('ethers');
const app = categorical();
const port = 3000;

// Contract data
const CONTRACT_ADDRESS = 'contract deal with'; 
const ABI = [
    
        "inputs": [],
        "stateMutability": "nonpayable",
        "sort": "constructor"
    ,
    
        "inputs": [
            
                "internalType": "uint256",
                "name": "collectionId",
                "type": "uint256"
            ,
            
                "internalType": "address",
                "name": "walletAddress",
                "type": "address"
            ,
            
                "internalType": "string",
                "name": "tokenURI",
                "type": "string"
            
        ],
        "title": "mintCard",
        "outputs": [],
        "stateMutability": "nonpayable",
        "sort": "perform"
    ,
    
        "inputs": [
            
                "internalType": "uint256",
                "name": "tokenId",
                "type": "uint256"
            
        ],
        "title": "tokenURI",
        "outputs": [
            
                "internalType": "string",
                "name": "",
                "type": "string"
            
        ],
        "stateMutability": "view",
        "sort": "perform"
    
];

// Arrange supplier and signer
const supplier = new ethers.suppliers.JsonRpcProvider('http://127.0.0.1:8545');
const walletPrivateKey = 'walletkey'; 
const signer = new ethers.Pockets(walletPrivateKey, supplier); // Create signer
const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, signer); // Join contract to signer

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

    attempt 
        const tx = await contract.mintCard(collectionId, walletAddress, tokenURI);
        await tx.wait(); // Anticipate the transaction to be confirmed
        res.standing(200).json( success: true, transactionHash: tx.hash );
     catch (error) 
        console.error(error);
        res.standing(500).json( success: false, message: error.message );
    
);

// API endpoint to get token data
app.get('/nft/:tokenId', async (req, res) => 
    const tokenId = req.params.tokenId; // Get tokenId from the request parameters
    attempt 
        const tokenURI = await contract.tokenURI(tokenId); // Name tokenURI perform
        res.json( tokenId, tokenURI ); // Reply with tokenId and tokenURI
     catch (error) 
        res.standing(400).json( error: 'Token not discovered' ); // Deal with error if token just isn't discovered
    
);

// Begin the server
app.pay attention(port, () => 
    console.log(`Server is working at http://localhost:$port`);
);

Downside:
When I attempt to name the /mint endpoint with this URL:
http://localhost:3000/mint/1/0xYourWalletAddressHere/https://metadata-url

I obtain an error saying :

node index.js     
Server is working at http://localhost:3000
<ref *1> Error: can't estimate gasoline; transaction might fail or might require handbook gasoline restrict [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"cause":"Error: Transaction reverted: perform selector was not acknowledged and there is no fallback perform","code":"UNPREDICTABLE_GAS_LIMIT","methodology":"estimateGas","transaction":"from":"Mywalletaddress","maxPriorityFeePerGas":"sort":"BigNumber","hex":"0x59682f00","maxFeePerGas":"sort":"BigNumber","hex":"0xc1b71080","to":"contractaddress","knowledge":"0xf2afa53c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b8d4736382c43a4ea117af8f57ed95823d42c6c0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000003b68747470733a2f2f74636772657075626c69632e636f6d2f6d656469612f62696e6172792f3030302f3530302f3233382f3530303233382e6a70670000000000","sort":2,"accessList":null,"error":"cause":"processing response error","code":"SERVER_ERROR","physique":""jsonrpc":"2.0","id":49,"error":"code":-32603,"message":"Error: Transaction reverted: perform selector was not acknowledged and there is no fallback perform","knowledge":"message":"Error: Transaction reverted: perform selector was not acknowledged and there is no fallback perform","knowledge":"0x"","error":"code":-32603,"knowledge":"message":"Error: Transaction reverted: perform selector was not acknowledged and there is no fallback perform","knowledge":"0x","requestBody":""methodology":"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="knowledge":"0xf2afa53c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b8d4736382c43a4ea117af8f57ed95823d42c6c0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000003b68747470733a2f2f74636772657075626c69632e636f6d2f6d656469612f62696e6172792f3030302f3530302f3233382f3530303233382e6a70670000000000","to":,"from":"0x7b8D4736382c43A4eA117AF8F57eD95823d42c6C","sort":2,"maxFeePerGas":"sort":"BigNumber","hex":"0xc1b71080","maxPriorityFeePerGas":"sort":"BigNumber","hex":"0x59682f00","nonce":,"gasLimit":,"chainId":, code=UNPREDICTABLE_GAS_LIMIT, model=abstract-signer/5.7.0)
    at Logger.makeError (/house/kali/collectible-card-game-daar/node_modules/@ethersproject/logger/lib/index.js:238:21)
    at Logger.throwError (/house/kali/collectible-card-game-daar/node_modules/@ethersproject/logger/lib/index.js:247:20)
    at /house/kali/collectible-card-game-daar/node_modules/@ethersproject/abstract-signer/lib/index.js:365:47
    at course of.processTicksAndRejections (node:inner/course of/task_queues:105:5)
    at async Promise.all (index 7) {
  cause: 'can't estimate gasoline; transaction might fail or might require handbook gasoline restrict',
  code: 'UNPREDICTABLE_GAS_LIMIT',
  error: Error: can't estimate gasoline; transaction might fail or might require handbook gasoline restrict [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (cause="Error: Transaction reverted: perform selector was not acknowledged and there is no fallback perform", methodology="estimateGas", transaction={"from":"walletadress","maxPriorityFeePerGas":"sort":"BigNumber","hex":"0x59682f00","maxFeePerGas":"sort":"BigNumber","hex":"0xc1b71080","to":"contractaddress","knowledge":"0xf2afa53c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b8

I even have a deployement script that include this code”└─$

cat 000001-deploy-game.ts 
import 'dotenv/config'
import  DeployFunction  from 'hardhat-deploy/sorts'

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


export default deployer

and an artifcat? json script with”

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


and one other principal.json with: ┌──(kali㉿kali)-[~/…/contracts/artifacts/src/Main.sol]
└─$ cat Primary.json

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

I am undecided what i am doing unsuitable i am completely new to this and I need assistance, thanks.

[ad_2]

Supply hyperlink