Skip to content

Commit

Permalink
feat(ctp): support deploy from PK (#3256)
Browse files Browse the repository at this point in the history
Makes it possible to easily deploy via PK if not deploying via Ledger.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
smartcontracts and mergify[bot] committed Aug 18, 2022
1 parent f53c30b commit ea371af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-pillows-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts-periphery': patch
---

Support deploy via Ledger or private key
5 changes: 4 additions & 1 deletion packages/contracts-periphery/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ ETHEREUM_ETHERSCAN_API_KEY=
# Etherscan API key for Optimism and Optimism testnets
OPTIMISTIC_ETHERSCAN_API_KEY=

# Ledger required to deploy stuff, insert address here
# Insert your Ledger address here if using a Ledger to deploy
LEDGER_ADDRESS=

# Alternatively you can use a private key, but leave Ledger blank if so
PRIVATE_KEY=

# Required to deploy to Ethereum or Ethereum testnets
INFURA_PROJECT_ID=
22 changes: 21 additions & 1 deletion packages/contracts-periphery/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import assert from 'assert'

import { HardhatUserConfig, subtask } from 'hardhat/config'
import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from 'hardhat/builtin-tasks/task-names'
import { getenv } from '@eth-optimism/core-utils'
Expand Down Expand Up @@ -29,11 +31,21 @@ subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(
}
)

assert(
!(getenv('PRIVATE_KEY') && getenv('LEDGER_ADDRESS')),
'use only one of PRIVATE_KEY or LEDGER_ADDRESS'
)

const accounts = getenv('PRIVATE_KEY')
? [getenv('PRIVATE_KEY')]
: (undefined as any)

const config: HardhatUserConfig = {
networks: {
optimism: {
chainId: 10,
url: 'https://mainnet.optimism.io',
accounts,
verify: {
etherscan: {
apiKey: getenv('OPTIMISTIC_ETHERSCAN_API_KEY'),
Expand All @@ -43,6 +55,7 @@ const config: HardhatUserConfig = {
'optimism-kovan': {
chainId: 69,
url: 'https://kovan.optimism.io',
accounts,
verify: {
etherscan: {
apiKey: getenv('OPTIMISTIC_ETHERSCAN_API_KEY'),
Expand All @@ -52,6 +65,7 @@ const config: HardhatUserConfig = {
'optimism-goerli': {
chainId: 420,
url: 'https://goerli.optimism.io',
accounts,
verify: {
etherscan: {
apiKey: getenv('OPTIMISTIC_ETHERSCAN_API_KEY'),
Expand All @@ -61,6 +75,7 @@ const config: HardhatUserConfig = {
ethereum: {
chainId: 1,
url: `https://mainnet.infura.io/v3/${getenv('INFURA_PROJECT_ID')}`,
accounts,
verify: {
etherscan: {
apiKey: getenv('ETHEREUM_ETHERSCAN_API_KEY'),
Expand All @@ -70,6 +85,7 @@ const config: HardhatUserConfig = {
goerli: {
chainId: 5,
url: `https://goerli.infura.io/v3/${getenv('INFURA_PROJECT_ID')}`,
accounts,
verify: {
etherscan: {
apiKey: getenv('ETHEREUM_ETHERSCAN_API_KEY'),
Expand All @@ -79,6 +95,7 @@ const config: HardhatUserConfig = {
ropsten: {
chainId: 3,
url: `https://ropsten.infura.io/v3/${getenv('INFURA_PROJECT_ID')}`,
accounts,
verify: {
etherscan: {
apiKey: getenv('ETHEREUM_ETHERSCAN_API_KEY'),
Expand All @@ -88,6 +105,7 @@ const config: HardhatUserConfig = {
kovan: {
chainId: 42,
url: `https://kovan.infura.io/v3/${getenv('INFURA_PROJECT_ID')}`,
accounts,
verify: {
etherscan: {
apiKey: getenv('ETHEREUM_ETHERSCAN_API_KEY'),
Expand Down Expand Up @@ -128,7 +146,9 @@ const config: HardhatUserConfig = {
},
namedAccounts: {
deployer: {
default: `ledger://${getenv('LEDGER_ADDRESS')}`,
default: getenv('LEDGER_ADDRESS')
? `ledger://${getenv('LEDGER_ADDRESS')}`
: 0,
hardhat: 0,
},
},
Expand Down

0 comments on commit ea371af

Please sign in to comment.