Skip to main content

Use Hardhat

Developing for Hyperledger Besu using Hardhat is the same as developing for public Ethereum networks using Hardhat. Hardhat supports Besu with the only difference being Besu does not support private key management. To use Besu with Hardhat, you must configure a wallet.

Use a HD wallet

To add the wallet provider, update the hardhat.config.ts file in the project directory. Replace:

  • <JSON-RPC-http-endpoint> with the JSON-RPC endpoint (IP address and port) of a Besu node.
  • <MY-ACCOUNT-MNEMONIC> with the list of words that make up your account's mnemonic.
  • <MY-PASSWORD> your password if used
  • <MY-ACCOUNT-PRIVATE-KEY> your account's private key
module.exports = {
// See <https://hardhat.org/hardhat-runner/docs/config#hd-wallet-config>
// for more about customizing your Hardhat configuration!
networks: {
besuWallet: {
url: "<JSON-RPC-http-endpoint>",
accounts: {
mnemonic: "<ACCOUNT-MNEMONIC>",
path: "m/44'/60'/0'/0",
initialIndex: 0,
count: 1,
passphrase: "",
},
},
},
};

Alternatively, via a private key in code

Please make sure you do not commit and private keys to source control like Github, always inject your keys at runtime as env vars, or use the likes of a vault.

const provider = new ethers.JsonRpcApiProvider(<JSON-RPC-http-endpoint>);
const wallet = new ethers.Wallet(<MY-ACCOUNT-PRIVATE-KEY>);
// connect the wallet to the provider
const signer = wallet.connect(provider);

Start a Besu node

Start a Besu node with JSON-RPC enabled on the endpoint specified in the Hardhat configuration file.

Deploy a contract

To deploy a contract onto the Besu network:

npx hardhat scripts run ./scripts/deploy_my_contract.ts --network besuWallet