I have build a smart contract with solidity, in this case I have compiled and test. I get 1 pass successfully waw. But when I deploy to BSC_TESTNET with command:
npx hardhat run scripts/deploy.js --network bsctest
I get error return: NETWORK_ERROR
require("@nomiclabs/hardhat-ethers");
require("dotenv").config();
require("@nomiclabs/hardhat-etherscan")
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.6.12",
settings: {
optimizer: true,
runs: 200
},
networks: {
dev: {
url: "http://localhost:7545",
gasPrice: 20,
saveDeployments: true
},
bsctest: {
url: "https://data-seed-prebsc-2-s2.binance.org:8545/",
accounts: [process.env.PRIV_KEY],
gasPrice: 10000000000,
blockGasLimit: 1000000
},
},
etherscan:{
apiKey:process.env.API_KEY
}
};
I will suggest you to re-check the API_KEY and you are accessing the .env files
You can use the following configuration.
require("@nomiclabs/hardhat-waffle");
require("dotenv").config();
require("@nomiclabs/hardhat-etherscan");
// hardhat.config.js
const { mnemonic, apiKey } = require("./secrets.json");
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: {
compilers: [
{
version: "0.6.12",
},
{
version: "0.5.16",
},
{
version: "0.6.0",
},
{
version: "0.4.18",
},
{
version: "0.6.6",
settings: {
optimizer: {
enabled: true,
runs: 1000,
},
},
},
],
},
networks: {
dev: {
url: "http://localhost:8545",
gasPrice: 50000000000,
saveDeployments: true,
},
bsctest: {
url: "https://data-seed-prebsc-2-s2.binance.org:8545/",
accounts: { mnemonic: mnemonic },
gasPrice: 10000000000,
blockGasLimit: 1000000,
},
// bsc: {
// url: "https://bsc-dataseed1.binance.org/",
// accounts: [process.env.PRIV_KEY],
// gasPrice: 5100000000,
// blockGasLimit: 1000000
// }
},
etherscan: {
apiKey: apiKey,
},
};
Make sure you are having a secret.json in the directory with following property
{
"url": "https://data-seed-prebsc-1-s1.binance.org:8545",
"apiKey": "",
"mnemonic": "",
"key": ""
}