Lesson 9 Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0) #5248
-
please help i am unable to deploy my code on sepolia testnet while i have deployed it on goerli several times whenever I do it gives this error Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0) been stuck for two days my lottery.sol <//Lottery
//Enter the Lottery(someone paying some amount)
//Pick a random winner(verifiably random)
//winner to be selected x minutes(completely automated)
//Chainlink Oracle =>Randomness,Automated Execution(Chainlink Keeper)
//SPDX-License-Identifier:MIT
pragma solidity ^0.8.7;
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AutomationCompatibleInterface.sol";
import "hardhat/console.sol";
error Raffle_NotEnoughEthEntered();
error Raffle_TransferFailed();
error Raffle__NotOpen();
error Raffle_upkeepNotNeeded(uint256 cuurentBalance, uint256 numPlayers, uint256 raffleState);
/**@title A sample Automated Contract
* @author Mohd Faizan Qureahi
* @notice This contract is creating an untempered decentralized smart contract
* @dev This implements Chainlink vrf and Chainlink Keepers
*/
contract Raffle is VRFConsumerBaseV2, AutomationCompatibleInterface {
/**Type Declarations */
enum RaffleState {
OPEN,
CALCULATING
} //uint256 0=OPEN,1=Closed
/**State Variables */
uint256 private immutable i_entranceFee;
address payable[] private s_players;
VRFCoordinatorV2Interface private immutable i_vrfCoordinator;
bytes32 private immutable i_gasLane;
uint64 private immutable i_subscriptionId;
uint16 private constant REQUEST_CONFIRMATIONS = 3;
uint32 private immutable i_callbackGasLimit;
uint32 private constant NUM_WORDS = 1;
/**Lottery Winner */
address private s_recentWinner;
RaffleState private s_RaffleState;
uint256 private s_lastTimeStamp;
uint256 private immutable i_interval;
/**Events */
event RaffleEnter(address indexed player);
event RequestedRaffleWinner(uint256 indexed requestId);
event WinnerPicked(address indexed winner);
/**Functions */
constructor(
address vrfCoordinatorV2, //contract
uint256 entranceFee,
bytes32 gaslane,
uint64 subscriptionId,
uint32 callbackGasLimit,
uint256 interval
) VRFConsumerBaseV2(vrfCoordinatorV2) {
i_entranceFee = entranceFee;
i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2);
i_gasLane = gaslane;
i_subscriptionId = subscriptionId;
i_callbackGasLimit = callbackGasLimit;
s_RaffleState = RaffleState.OPEN;
s_lastTimeStamp = block.timestamp;
i_interval = interval;
}
function enterRaffle() public payable {
if (msg.value < i_entranceFee) {
revert Raffle_NotEnoughEthEntered();
}
if (s_RaffleState != RaffleState.OPEN) {
revert Raffle__NotOpen();
}
s_players.push(payable(msg.sender));
emit RaffleEnter(msg.sender);
}
/**this is the function that chainlink keeper nodes call
* they lokk for the `upKeepNeeded` to return true
* The following shoulb be true in order for it to be true
* 1.Our time interval must have passed
* 2.the should have atleast one player and have some ETH
* 3.Our subscription is funded with Link
* 4. The Lottery should be in open state
*/
function checkUpkeep(
bytes memory /*checkData*/
) public view override returns (bool upkeepNeeded, bytes memory /*performData*/) {
bool isOpen = (RaffleState.OPEN == s_RaffleState);
bool timePassed = ((block.timestamp - s_lastTimeStamp) > i_interval);
bool hasPlayers = (s_players.length > 0);
bool hasBalance = address(this).balance > 0;
upkeepNeeded = (isOpen && timePassed && hasPlayers && hasBalance);
return (upkeepNeeded, "0x0");
}
function performUpkeep(bytes calldata /*performData */) external override {
(bool upkeepNeeded, ) = checkUpkeep("");
if (!upkeepNeeded) {
revert Raffle_upkeepNotNeeded(
address(this).balance,
s_players.length,
uint256(s_RaffleState)
);
}
/**Request the random number */
/** then do something with that Random number*/
/**it takes 2 transaction */
s_RaffleState = RaffleState.CALCULATING;
uint256 requestId = i_vrfCoordinator.requestRandomWords(
i_gasLane /**keyhash */,
i_subscriptionId,
REQUEST_CONFIRMATIONS,
i_callbackGasLimit,
NUM_WORDS
);
emit RequestedRaffleWinner(requestId);
}
function fulfillRandomWords(
uint256 /*requestId*/,
uint256[] memory randomWords
) internal override {
uint256 indexOfWinner = randomWords[0] % s_players.length;
address payable recentWinner = s_players[indexOfWinner];
s_recentWinner = recentWinner;
s_RaffleState = RaffleState.OPEN;
s_players = new address payable[](0);
s_lastTimeStamp = block.timestamp;
(bool success, ) = recentWinner.call{value: address(this).balance}("");
if (!success) {
revert Raffle_TransferFailed();
}
emit WinnerPicked(recentWinner);
}
/**View, Pure Functions */
function getEntranceFee() public view returns (uint256) {
return i_entranceFee;
}
function getPlayer(uint256 index) public view returns (address) {
return s_players[index];
}
function getRecentWinner() public view returns (address) {
return s_recentWinner;
}
function getRaffleState() public view returns (RaffleState) {
return s_RaffleState;
}
function getNumWords() public pure returns (uint256) {
return NUM_WORDS;
}
function getNumberOfPlayers() public view returns (uint256) {
return s_players.length;
}
function getLatestTimeStamp() public view returns (uint256) {
return s_lastTimeStamp;
}
function getRequestConfirmations() public pure returns (uint256) {
return REQUEST_CONFIRMATIONS;
}
function getInterval() public view returns (uint256) {
return i_interval;
}
}
> deploy-raffle.js 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()
let vrfCoordinatorV2Address, subscriptionId, vrfCoordinatorV2Mock
const chainId = network.config.chainId
if (developmentChains.includes(network.name)) {
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait(1)
subscriptionId = transactionReceipt.events[0].args.subId
//Fund the subscription
//Usually on the real network you need the link token
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)) {
await vrfCoordinatorV2Mock.addConsumer(subscriptionId, raffle.address)
log("Consumer is added")
}
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
log("Verifying...")
await verify(raffle.address, args)
}
log("-------------------------------")
}
module.exports.tags = ["all", "raffle"] helper-hardhat-config.js const { ethers } = require("hardhat")
const networkConfig = {
5: {
name: "goerli",
vrfCoordinatorV2: "0x2ca8e0c643bde4c2e08ab1fa0da3401adad7734d",
entranceFee: ethers.utils.parseEther("0.01"),
gasLane: "0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15", // 150 gwei
subscriptionId: "11118",
callbackGasLimit: "500000", // 500,000 gas
keepersUpdateInterval: "30",
},
31337: {
name: "hardhat",
entranceFee: ethers.utils.parseEther("0.01"),
gasLane: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c", // 30 gwei
callbackGasLimit: "500000", // 500,000 gas
keepersUpdateInterval: "30",
},
11155111: {
name: "sepolia",
subscriptionId: "961",
gasLane: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c", // 30 gwei
keepersUpdateInterval: "30",
raffleEntranceFee: ethers.utils.parseEther("0.01"), // 0.01 ETH
callbackGasLimit: "500000", // 500,000 gas
vrfCoordinatorV2: "0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625",
},
}
const developmentChains = ["hardhat", "localhost"]
module.exports = {
networkConfig,
developmentChains,
} hardhat.config.js
raffle.staging.test.js const { assert, expect } = require("chai")
const { network, getNamedAccounts, deployments, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../../helper-hardhat-config")
developmentChains.includes(network.name)
? describe.skip
: describe("Raffle unit tests", function () {
let raffle, raffleEntranceFee, deployer
beforeEach(async function () {
deployer = (await getNamedAccounts()).deployer
raffle = await ethers.getContract("Raffle", deployer)
raffleEntranceFee = await raffle.getEntranceFee()
})
describe("fulfillRandomWords", function () {
it("works with Chainlink keepers and Chainlink Vrf,we get a random winner", async function () {
console.log("Setting up test...")
const startingTimeStamp = await raffle.getLatestTimeStamp()
const accounts = await ethers.getSigners()
console.log("Setting up the listener")
await new Promise(async (resolve, reject) => {
//setup the listener before we enter the raffle
//just in case blockchain moves really fast
raffle.once("WinnerPicked", async function () {
console.log("WinnerPicked event fired!")
try {
const recentWinner = await raffle.getRecentWinner()
const raffleState = await raffle.getRaffleState()
const winnerEndingBalance = await accounts[0].getBalance()
const endingTimeStamp = await raffle.getLatestTimeStamp()
//asserts
await expect(raffle.getPlayer(0)).to.be.reverted
assert.equal(recentWinner.toString(), accounts[0].address)
assert.equal(raffleState, 0)
assert.equal(
winnerEndingBalance.toString(),
winnerStartingBalance.add(raffleEntranceFee).toString()
)
assert(endingTimeStamp > startingTimeStamp)
resolve()
} catch (error) {
console.log(error)
reject(error)
}
})
//Then entering the raffle
console.log("Entering the raffle")
const tx = await raffle.enterRaffle({ value: raffleEntranceFee })
await tx.wait(1)
const winnerStartingBalance = await accounts[0].getBalance()
//and this code won't complete until our listener has finished listening
})
})
})
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@highHumann In the network config settings your fee variable name is this; raffleEntranceFee: ethers.utils.parseEther("0.01"), but in the args, in the deploy file, it is this; const entranceFee = networkConfig[chainId]["entranceFee"] Also make sure other variables, you can console log the args array to see all values and verify which value is undefined. |
Beta Was this translation helpful? Give feedback.
@highHumann In the network config settings your fee variable name is this;
but in the args, in the deploy file, it is this;
Also make sure other variables, you can console log the args array to see all values and verify which value is undefined.