npm install --save-dev hardhat
npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers
mkdir MegaCoin
cd MegaCoin
$ npx hardhat
888 888 888 888 888
888 888 888 888 888
888 888 888 888 888
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
888 888 "88b 888P" d88" 888 888 "88b "88b 888
888 888 .d888888 888 888 888 888 888 .d888888 888
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
Welcome to Hardhat v2.0.8
? What do you want to do? …
❯ Create a sample project
Create an empty hardhat.config.js
Quit
require("@nomiclabs/hardhat-waffle");
require('@nomiclabs/hardhat-ethers');
const { mnemonic } = 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 () => {
const accounts = await 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 = {
defaultNetwork: "mainnet",
networks: {
localhost: {
url: "http://127.0.0.1:8545"
},
hardhat: {
},
testnet: {
url: "https://data-seed-prebsc-1-s1.binance.org:8545",
chainId: 97,
gasPrice: 20000000000,
accounts: {mnemonic: mnemonic}
},
mainnet: {
url: "https://bsc-dataseed.binance.org/",
chainId: 56,
gasPrice: 20000000000,
accounts: {mnemonic: mnemonic}
}
},
solidity: {
version: "0.5.16",
settings: {
optimizer: {
enabled: true
}
}
},
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts"
},
mocha: {
timeout: 20000
}
};
它需要為 Provider 傳入助記詞,這是您要部署的帳戶的助記詞。 在根目錄中創建一個新的 .secret 文件並輸入您的 12 字助記詞助記詞以開始使用。 要從 metamask 錢包中獲取種子詞,您可以轉到 Metamask 設置,然後從菜單中選擇安全和隱私,您將在其中看到一個顯示種子詞的按鈕。
$ npx hardhat run --network testnet scripts/deploy.js
請記住您提供的地址、transaction_hash 和其他詳細信息會有所不同,以上只是提供一個結構概念。