Skip to content

Commit

Permalink
Merge pull request #77 from multiversx/added-hardhat-ledger-support
Browse files Browse the repository at this point in the history
Added hardhat ledger support
  • Loading branch information
dragos-rebegea authored Nov 7, 2024
2 parents c73cc37 + 6a989f6 commit 8c18a1f
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docker/build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM node:22-alpine AS sol-compiler
FROM node:22-bookworm AS sol-compiler
LABEL description="This Docker image compiles the Solidity contracts and prepares the .json and .hex files."

WORKDIR /multiversx
COPY . .

RUN apk update && apk add jq
RUN apt update && apt -qy install jq

RUN cp -u .env.example .env

Expand Down
78 changes: 53 additions & 25 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@nomiclabs/hardhat-ethers";
import "@nomicfoundation/hardhat-toolbox";
import "@openzeppelin/hardhat-upgrades";
import "@nomicfoundation/hardhat-ledger";

import "./tasks/accounts";
import "./tasks/clean";
Expand Down Expand Up @@ -64,16 +65,28 @@ if (!infuraApiKey) {
throw new Error("Please set your INFURA_API_KEY in a .env file");
}

function getETHConfig(network: string): NetworkUserConfig {
let config = {
accounts: {
count: 12,
mnemonic,
path: "m/44'/60'/0'/0",
initialIndex: Number(initialindex),
},
url: "https://" + chainIds.sepolia + ".infura.io/v3/" + infuraApiKey,
};
function getETHConfig(network: string, withLedger: boolean): NetworkUserConfig {
let config: any

if (withLedger) {
config = {
ledgerAccounts: [
"0x60745fCA64C92c0aBAC5b1bed145204FBF1e9d85",
],
ledgerOptions: {
derivationFunction: (x: string) => `m/44'/60'/0'/0/${x}`
},
};
} else {
config = {
accounts: {
count: 12,
mnemonic,
path: "m/44'/60'/0'/0",
initialIndex: Number(initialindex),
},
};
}

switch (network) {
case "testnet":
Expand All @@ -89,16 +102,28 @@ function getETHConfig(network: string): NetworkUserConfig {
return config;
}

function getBSCConfig(network: string): NetworkUserConfig {
let config = {
accounts: {
count: 12,
mnemonic,
path: "m/44'/60'/0'/0",
initialIndex: Number(initialindex),
},
url: `https://data-seed-prebsc-1-s1.binance.org:8545`,
};
function getBSCConfig(network: string, withLedger: boolean): NetworkUserConfig {
let config: any

if (withLedger) {
config = {
ledgerAccounts: [
"0x60745fCA64C92c0aBAC5b1bed145204FBF1e9d85",
],
ledgerOptions: {
derivationFunction: (x: string) => `m/44'/60'/0'/0/${x}`
},
};
} else {
config = {
accounts: {
count: 12,
mnemonic,
path: "m/44'/60'/0'/0",
initialIndex: Number(initialindex),
},
};
}

switch (network) {
case "testnet":
Expand All @@ -115,7 +140,7 @@ function getBSCConfig(network: string): NetworkUserConfig {
}

function getPolygonConfig(network: string): NetworkUserConfig {
let config = {
const config = {
accounts: {
count: 12,
mnemonic,
Expand Down Expand Up @@ -155,10 +180,13 @@ const config: HardhatUserConfig = {
},
chainId: chainIds.hardhat,
},
sepolia: getETHConfig("testnet"),
mainnet_eth: getETHConfig("mainnet"),
testnet_bsc: getBSCConfig("testnet"),
mainnet_bsc: getBSCConfig("mainnet"),
sepolia: getETHConfig("testnet", false),
mainnet_eth: getETHConfig("mainnet", false),
mainnet_eth_ledger: getETHConfig("mainnet", true),
testnet_bsc: getBSCConfig("testnet", false),
testnet_bsc_ledger: getBSCConfig("testnet", true),
mainnet_bsc: getBSCConfig("mainnet",false),
mainnet_bsc_ledger: getBSCConfig("mainnet", false),
mumbai: getPolygonConfig("testnet"),
mainnet_polygon: getPolygonConfig("mainnet"),
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomicfoundation/ignition-core": "^0.15.5",
"@nomicfoundation/hardhat-ledger": "1.0.3",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.8",
"@openzeppelin/contracts": "^5.0.1",
Expand Down
Loading

0 comments on commit 8c18a1f

Please sign in to comment.