简体   繁体   中英

How to pass value of function and parameters to smart contract ethersjs?

I am trying to interact with my smart contract using the ethers.js library, but an error appears when I try to call a function from the smart contract that takes the value of the transaction and a _count parameter.

Error I get:

Error: invalid BigNumber value 
(argument="value", value={"value":{"type":"BigNumber","hex":"0x016345785d8a0000"},"_count":{"type":"BigNumber","hex":"0x02"}}, code=INVALID_ARGUMENT, version=bignumber/5.6.2)

Smart contract code:

function mint(uint256 _count) payable external returns (uint256) {
    ...code...    
    if (msg.value != price * _count) {
            revert IncorrectPrice(msg.value, price * _count);
    }
   ...code...
}

Ethers.js contract call:

await contract.mint({
        value: ethers.utils.parseEther("0.1"),
        _count: ethers.BigNumber.from(2),
});

Can anybody help?

Thanks in advance!

I don't think you can put the function arguments inside the object. Try this

await contract.mint(2, {
        value: ethers.utils.parseEther("0.1")
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM