This error:
TypeError: GetNamedAccounts is not a function
gets printed when i try to deploy my contract with this piece of code:
yarn hardhat deploy --network sepolia
I've tinkered with dependencies for a few hours and here's what i ended up with (and it's still doesn't work):
// hardhat.config.js
require("dotenv").config();
require("@nomiclabs/hardhat-waffle");
require("hardhat-deploy");
require("hardhat-deploy-ethers");
require("@nomiclabs/hardhat-etherscan");
const SEPOLIA = process.env.SEPOLIA_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
module.exports = {
solidity: "0.8.23",
networks: {
sepolia: {
url: `${SEPOLIA}`,
chainId: 11155111,
accounts: [PRIVATE_KEY],
},
localhost: {
url: "http://127.0.0.1:8545/",
chainId: 31337,
},
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
namedAccounts: {
deployer: {
default: 4,
11155111: process.env.PRIVATE_KEY,
},
},
};
// package.json
{
...
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"@nomiclabs/hardhat-etherscan": "^3.1.8",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@types/mocha": "^10.0.6",
"chai": "^4.2.0",
"hardhat-deploy": "^0.11.45",
"hardhat-gas-reporter": "^1.0.8",
"solidity-coverage": "^0.8.0"
},
"dependencies": {
"@chainlink/contracts": "^0.8.0",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"dotenv": "^16.3.1",
"ethers": "^6.10.0",
"hardhat": "^2.19.4",
"hardhat-deploy-ethers": "^0.4.1"
}
}
Here's the deploy script (i try to use hardhat-deploy plugin as you may have guessed):
module.exports = async ({deployments, GetNamedAccounts}) => {
const { deploy } = deployments;
const deployer = (await GetNamedAccounts()).deployer;
const elections = await deploy('Elections', {
from: deployer,
args: [],
log: true,
confirmations: 3,
});
if ((network.config.chainId == 11155111) && process.env.ETHERSCAN_API_KEY) {
await verify(elections.address, []);
};
};
I would be extremely thankful if somebody helped me (please)
Yes man, it indeed helped, thanks! I was so convinced i spelled it correctly i didn't check it.. I'm getting another error now though:
Error: ERROR processing /home/andrii/Documents/Elections/ElectionsBackEnd/deploy/01-deploy-elections.js:
TypeError: Cannot read properties of undefined (reading 'length')
at getFrom (/home/andrii/Documents/Elections/ElectionsBackEnd/node_modules/hardhat-deploy/src/helpers.ts:1642:14)
I do this:
const { deployer } = await getNamedAccounts();
console.log(`Deployer is ${deployer}`);
and it prints that 'Deployer is undefined
'..