javascript - ethers js exits with this error=> invalid BigNumber value (argument="value", value=undefin

I tried to send a request to my contract using ethersjs like this:const web3Modal = new Web3Modal()co

I tried to send a request to my contract using ethersjs like this:

const web3Modal = new Web3Modal()
const connection = await web3Modal.connect()
const provider = new ethers.providers.Web3Provider(connection)
const signer = provider.getSigner()
const contract = new ethers.Contract(Contract, Market.abi, signer)
const price = ethers.utils.parseUnits(price.toString(), 18)

//const price = web3.utils.toWei(nft.price);
//const price = ethers.BigNumber.from(nft.price.toString()).toHexString();
   
const transaction = await contract.createSale(address, price)

await transaction.wait()

This code shows an error, I have tried all the solutions in this world, but nothing worked. => versions: nodejs 14.15, npm 8, web3 1.6, ethers 5.5

Any help?

Unhandled Rejection (Error): invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.5.0)

I tried to send a request to my contract using ethersjs like this:

const web3Modal = new Web3Modal()
const connection = await web3Modal.connect()
const provider = new ethers.providers.Web3Provider(connection)
const signer = provider.getSigner()
const contract = new ethers.Contract(Contract, Market.abi, signer)
const price = ethers.utils.parseUnits(price.toString(), 18)

//const price = web3.utils.toWei(nft.price);
//const price = ethers.BigNumber.from(nft.price.toString()).toHexString();
   
const transaction = await contract.createSale(address, price)

await transaction.wait()

This code shows an error, I have tried all the solutions in this world, but nothing worked. => versions: nodejs 14.15, npm 8, web3 1.6, ethers 5.5

Any help?

Unhandled Rejection (Error): invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.5.0)

Share Improve this question edited Oct 3, 2022 at 19:45 TylerH 21.1k79 gold badges79 silver badges114 bronze badges asked Nov 4, 2021 at 16:35 kkokko 432 silver badges9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

When I connect to metamask in my frontend, the below error was happened.

invalid BigNumber string (argument="value", value="1.2e+21", code=INVALID_ARGUMENT, version=bignumber/5.5.0)

I have fixed it with bignumber in ethers. If you are using web3.js version : 1.5.1, please try it in this way. And also in other version you can try to use bignumber.js and web3.utils.toBn.

import { BigNumber} from 'ethers';

....

const decimals = 18;
const trans_amount = 1500;
const amount= BigNumber.from(trans_amount).mul(BigNumber.from(10).pow(decimals));

It looks like your price variable has the value undefined when you call createSale, resulting in an error.

Your issue is similar to: https://ethereum.stackexchange./questions/111042/cant-send-ether-to-smart-contract-using-ethers-js

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745245780a4618404.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信