0

i am getting this error

TypeError: Cannot read properties of null (reading 'sendTransaction')

when i run the following command :

yarn hardhat run scripts/deploy.js --network Sepolia

deploy.js :

const { ethers } = require("hardhat")

async function main() {
    const SimpleStorageFactory = await ethers.getContractFactory(
        "SimpleStorage"
    )
    console.log("Deploying the contract...")
    const SimpleStorage = await SimpleStorageFactory.deploy()
    await SimpleStorage.deployed()
    console.log(`Contract deployed at address: ${SimpleStorage.address}`)
}

main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error)
        process.exit(1)
    })

hardhat.config.js :

require("@nomicfoundation/hardhat-toolbox")
require("dotenv").config()
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
    defaultNetwork: "hardhat",
    networks: {
        Sepolia: {
            url: SEPOLIA_RPC_URL,
            accounts: PRIVATE_KEY,
            chainId: 11155111,
        },
    },
    solidity: "0.8.18",
}
4
  • Try this in the config file [PRIVATE_KEY] Commented Mar 24, 2023 at 6:11
  • If i use [PRIVATE_KEY], then I get the following error , There's one or more errors in your config file * Invalid account: #0 for network: Sepolia - Expected string, received undefined Commented Mar 24, 2023 at 9:07
  • Are you taking the Private Key as a string, ie, in " "? It shouldn't be like that. Commented Mar 24, 2023 at 13:02
  • Thank you !!! Its working now Commented Mar 24, 2023 at 18:50

1 Answer 1

0

You should put your accounts inside an array: accounts: [PRIVATE_KEY] and make sure everything in your .env file is correct. If u still getting error try to console.log() your env variables to see your dotenv package is working fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.