我尝试将自己的 Gas 值转换为 BigInts、数字、字符串和 JSBI,更改数字值等
我还查看了其他一些答案,但没有解决错误
预期结果:交易通过并批准通过 routerAddress 进行支出
错误:
TypeError: invalid BigNumberish value (argument="value", value={ "hex": "0xb3e3", "type": "BigNumber" }, code=INVALID_ARGUMENT, version=6.4.2)
at makeError (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/utils/errors.js:113:21)
at assert (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/utils/errors.js:136:15)
at assertArgument (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/utils/errors.js:147:5)
at getBigInt (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/utils/maths.js:90:5)
at set gasLimit [as gasLimit] (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/transaction/transaction.js:327:44)
at Transaction.from (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/transaction/transaction.js:667:29)
at Wallet.sendTransaction (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/providers/abstract-signer.js:181:35)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async send (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/contract/contract.js:199:20)
at async Proxy.approve (file:///home/celestial/Documents/projects/auto-trading/web/node_modules/ethers/lib.esm/contract/contract.js:232:16) {
code: 'INVALID_ARGUMENT',
argument: 'value',
value: [BigNumber]
运行审批功能的代码(错误部分)
// goerli chain
const wethAddress = '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6';
const routerAddress = '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45';
const provider = new JsonRpcProvider(PROVIDER_URL);
const approvalContract = new Contract(wethAddress, erc20Abi, provider);
console.log('approving');
await approvalContract.connect(wallet).approve(
routerAddress,
6500000000000000
);
console.log('approved');
如有任何帮助,我们将不胜感激,谢谢!
您看到的错误基本上表明 ethersjs 现在发送了
BigInt
非常规 Number
类型。
您只需将发送的号码解析为
BigInt
即可解决此问题
const approvalContract = new Contract(wethAddress, erc20Abi, provider);
await approvalContract.connect(wallet).approve(
routerAddress,
BigInt("6500000000000000")
);
对于 ethers.js v6 我会这样写:
const approvalContract = new Contract(wethAddress, erc20Abi, provider);
await approvalContract.connect(wallet)["approve(address, uint256)"](
routerAddress,
BigInt("6500000000000000"))
请务必检查合约中函数参数的数据类型并按照此处的方式使用它们
["approve(address, uint256)"]
❤