首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法理解这个“无效BigNumber”错误是从哪里来的?

无法理解这个“无效BigNumber”错误是从哪里来的?
EN

Ethereum用户
提问于 2022-10-30 13:38:46
回答 1查看 261关注 0票数 0

我正在从事一项彩票dapp的工作,我在本地网络上部署我的合同时面临着一个问题。

我没有很大的经验调试这样的代码,我有点迷路了。

我可以从错误日志中清楚地看到,这个问题大约是一个很大的数值,但我无法理解代码中的问题在哪里,因为我无法从错误本身得到任何明确的解释。

有什么想法吗?

下面是部署的代码:

代码语言:javascript
复制
const { network, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")

const VRF_SUB_FUND_AMOUNT = ethers.utils.parseEther("2")

module.exports = async function ({ getNamedAccounts, deployments }) {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId
    let vrfCoordinatorV2Address, subscriptionId, vrfCoordinatorV2Mock

    if (developmentChains.includes(network.name)) {
        vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
        vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
        const transactionRepsonse = await vrfCoordinatorV2Mock.createSubscription()
        const transactionReceipt = await transactionRepsonse.wait(1)
        subscriptionId = transactionReceipt.events[0].args.subId
        await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT)
    } else {
        vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
        subscriptionId = networkConfig[chainId]["subscriptionId"]
    }

    const entranceFee = networkConfig[chainId]["entranceFee"]
    const gasLane = networkConfig[chainId]["gasLane"]
    const callbackGasLimit = networkConfig[chainId]["callbackGasLimit"]
    const keepersUpdateInterval = networkConfig[chainId]["keepersUpdateInterval"]

    const args = [
        vrfCoordinatorV2Address,
        entranceFee,
        gasLane,
        subscriptionId,
        callbackGasLimit,
        keepersUpdateInterval,
    ]
    const raffle = await deploy("Raffle", {
        from: deployer,
        args: args,
        log: true,
        waitConfirmations: network.config.blockConfirmations || 1,
    })

    if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
        log("Verifying...")
        await verify(raffle.address, args)
    }
    log("----------------------------------------------------------------")
}

module.exports.tags = ["all", "raffle"]

以下是错误日志:

代码语言:javascript
复制
PS C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp> yarn hardhat deploy
yarn run v1.22.19
warning package.json: No license field
$ "C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\.bin\hardhat" deploy
Nothing to compile
Local network detected! Deploying mocks...
deploying "VRFCoordinatorV2Mock" (tx: 0xcc454aa73563f7b97237e5ab1ed0859f0eaeea6abea666542e0455b43d97ace6)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 2526713 gas
Mocks Deployed!
----------------------------------------------------------
You are deploying to a local network, you'll need a local network running to interact
Please run `yarn hardhat console --network localhost` to interact with the deployed smart contracts!
----------------------------------------------------------
An unexpected error occurred:

Error: ERROR processing C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\deploy\01- deploy-raffle.js:
Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0)
    at Logger.makeError (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
    at Logger.throwError (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
    at Logger.throwArgumentError (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\logger\src.ts\index.ts:285:21)
    at Function.BigNumber.from (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\bignumber\src.ts\bignumber.ts:289:23)
    at NumberCoder.encode (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\abi\src.ts\coders\number.ts:25:27)
    at C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\abi\src.ts\coders\array.ts:71:19
    at Array.forEach (<anonymous>)
    at pack (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\abi\src.ts\coders\array.ts:54:12)
    at TupleCoder.encode (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\abi\src.ts\coders\tuple.ts:54:20)
    at AbiCoder.encode (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\@ethersproject\abi\src.ts\abi-coder.ts:111:15)
    at DeploymentsManager.executeDeployScripts (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1222:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at runNextTicks (node:internal/process/task_queues:65:3)
    at listOnTimeout (node:internal/timers:528:9)
    at processTimers (node:internal/timers:502:7)
    at DeploymentsManager.runDeploy (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\hardhat-deploy\src\DeploymentsManager.ts:1052:5)
    at SimpleTaskDefinition.action (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\hardhat-deploy\src\index.ts:438:5)
    at Environment._runTaskDefinition (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\hardhat\src\internal\core\runtime-environment.ts:308:14)
    at Environment.run (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\hardhat\src\internal\core\runtime-environment.ts:156:14)
    at SimpleTaskDefinition.action (C:\Users\User\Documents\GitHub\Blockchain\Ethereum\Smart-Lottery dApp\node_modules\hardhat-deploy\src\index.ts:584:32)
error Command failed with exit code 1.
EN

回答 1

Ethereum用户

回答已采纳

发布于 2022-11-02 14:21:38

上述错误是由于args数组中的参数定位错误造成的。

在创建deploy.js文件时,您应该遵循与创建raffle.sol文件相同的顺序。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/138432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档