Megabyte
Megabyte

Reputation: 139

Error: invalid BigNumber value (argument="value", value={"value":"25000000000000000"}, code=INVALID_ARGUMENT, version=bignumber/5.5.0)

I have tried changing the values from 0.025 ether to 1 ether then also its showing the same error.

Also, I have tried with the rational number like 1/8 still not working.

LOOKED into some answers but they didn't resolve the error.

I have the same code in other project and it's working over there.

Error Which I received

Uncaught (in promise) Error: invalid BigNumber value (argument="value", value={"value":"25000000000000000"}, code=INVALID_ARGUMENT, version=bignumber/5.5.0)

Could not get the stack frames of error: TypeError: Cannot read properties of null (reading 'length')

Image of the Error [1] [2]

Here is my Code for the Listing Price

    uint256 listingPrice = 0.025 ether ; // Here ether is denoting the MATIC

function getListingPrice() public view returns (uint256) {
        return listingPrice;
    }

Here is the Code for fetching the value in UI

async function putItem(url) {
    const web3Modal = new Web3Modal();
    const connection = await web3Modal.connect();
    const provider = new ethers.providers.Web3Provider(connection);
    const signer = provider.getSigner();

    const { royalty } = formInput;

    //NFT Contract
    let contract = new ethers.Contract(nftAddress, NFT.abi, signer);
    //minting the certificate
    let transaction = await contract.createToken(url);
    //waiting for the minting transaction to finish

    let tx = await transaction.wait();
    let event = tx.events[0];
    let value = event.args[2];
    let tokenId = value.toNumber(); //Token Id Of the NFT
    console.log(tokenId)

    //NFT Market Contract
    contract = new ethers.Contract(nftMarketAddress, NFTMarket.abi, signer);

    //fetching listing price from the contract
    let listingPrice = await contract.getListingPrice();
    listingPrice = listingPrice.toString();

    //listing the certificate. 
    transaction = await contract.createMarketItem(
      nftAddress,
      tokenId,
      { value: (listingPrice) },
      royalty,
      index
    );
    //waiting for the transaction to complete
    await transaction.wait();
    console.log("completed")

    //navigate back to home page

  }

If any more detail required, please comment.

Upvotes: 7

Views: 23915

Answers (5)

Yilmaz
Yilmaz

Reputation: 49681

I think this is the issue:

transaction = await contract.createMarketItem(
      nftAddress,
      tokenId,
      { value: (listingPrice) },
      royalty,
      index
    );

{ value: (listingPrice) }, is supposed to be object that represents the amount of money you are sending along side the transaction and it should be the last parameter in the function. Because looks like you are creating an NFT market item and you have to pay the price of listing.

Since you are creating an nft, looks like you have a const { royalty } = formInput. I believe you wanted to send the nft price instead of { value: (listingPrice) }. so your transaction should be like this

transaction = await contract.createMarketItem(
          nftAddress,
          tokenId,
          // I assume you want to send the nft price here from form
          priceFromForm,
          royalty,
          index, 
          // this should be the last parameter
          { value: (listingPrice) }

        );

Upvotes: 1

user3441246
user3441246

Reputation: 73

For my case I needed to add .toString() to the BigNumber before passing it to the contract.

async changePayoutAmount_ether(amount_ether) {
    let amount_wei = new BigNumber(amount_ether).shiftedBy(18).toString()
    await this.state.pcrContract.methods.setPayoutAmount(amount_wei).send({from: this.state.account}).then(console.log)
}

Also for anyone troubleshooting, note that there are at least two BigNumber libraries: I believe this error comes from this one but be careful if you're reading docs from the ethers.js one because the syntax for the constructors is different.

Upvotes: 3

Liam Pillay
Liam Pillay

Reputation: 816

It looks like you're trying to send an object as the parameter { value: (listingPrice) }

This should probably be written as either an array of parameters or just the listingPrice

//listing the certificate. 
transaction = await contract.createMarketItem(
  nftAddress,
  tokenId,
  listingPrice,
  royalty,
  index
);

Source: https://docs.ethers.io/v5/api/contract/contract/#contract-functionsSend

Upvotes: 4

Damian Willis
Damian Willis

Reputation: 1

You can use the following module:

import converter form "ethereum-uint-converter"

And if you want to know more detail, click here.

Upvotes: 0

tumbweed
tumbweed

Reputation: 11

I got this error as well. In my case, I forgot to update the ABI.

Upvotes: 1

Related Questions