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

5

7

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.

Mihrab answered 20/2, 2022 at 7:31 Comment(4)
Did you ever get to the bottom of this? I'm having the same issueVinculum
Hello , you are overflowing so i suggest you may convert that number to what javascript permits , i think it's around 9007199254740991, for solidity is way bigger so you may check it.Amenity
I got the smilier error like this, what is the solution?Despond
The only solution I found is to deploy and run tests on the testnet.Mihrab
G
4

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

Gunslinger answered 8/4, 2022 at 15:9 Comment(0)
F
3

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.

Fermentation answered 20/5, 2022 at 11:21 Comment(1)
cannot call constructor directly; use BigNumber.from This solution works but you have to add from()Mccall
M
1

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

Marconigraph answered 24/2, 2022 at 12:8 Comment(0)
U
1

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) }

        );
Ulrike answered 14/8, 2022 at 7:11 Comment(0)
C
0

You can use the following module:

import converter form "ethereum-uint-converter"

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

Commandeer answered 26/2, 2022 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.