Skip to content

Commit

Permalink
fix: deployment from private key in foundry
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedali8 committed Jan 5, 2024
1 parent aa7d496 commit a1a16a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
16 changes: 8 additions & 8 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,30 @@
localhost = "http://localhost:8545"

# ETHEREUM
goerli = "https://goerli.infura.io/v3/${API_KEY_INFURA}"
mainnet = "https://eth-mainnet.g.alchemy.com/v2/${API_KEY_ALCHEMY}"
sepolia = "https://sepolia.infura.io/v3/${API_KEY_INFURA}"
goerli = "https://goerli.infura.io/v3/${INFURA_API_KEY}"
mainnet = "https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
sepolia = "https://sepolia.infura.io/v3/${INFURA_API_KEY}"

# BINANCE SMART CHAIN
bnb_smart_chain = "https://bsc-dataseed.binance.org"
bnb_smart_chain_testnet = "https://rpc.ankr.com/bsc_testnet_chapel"

# MATIC/POLYGON
polygon = "https://polygon-mainnet.infura.io/v3/${API_KEY_INFURA}"
polygon = "https://polygon-mainnet.infura.io/v3/${INFURA_API_KEY}"
polygon_mumbai = "https://polygon-mumbai.infura.io/v3/${INFURA_API_KEY}"

# OPTIMISM
optimism = "https://optimism-mainnet.infura.io/v3/${API_KEY_INFURA}"
optimism = "https://optimism-mainnet.infura.io/v3/${INFURA_API_KEY}"
optimism_goerli = "https://optimism-goerli.infura.io/v3/${INFURA_API_KEY}"

# ARBITRUM
arbitrum_nova = ""
arbitrum_one = "https://arbitrum-mainnet.infura.io/v3/${API_KEY_INFURA}"
arbitrum_one = "https://arbitrum-mainnet.infura.io/v3/${INFURA_API_KEY}"
arbitrum_one_goerli = "https://arbitrum-goerli.infura.io/v3/${INFURA_API_KEY}"

# AVALANCHE
avalanche = "https://avalanche-mainnet.infura.io/v3/${API_KEY_INFURA}"
avalanche_fuji = "https://avalanche-fuji.infura.io/v3/${API_KEY_INFURA}"
avalanche = "https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}"
avalanche_fuji = "https://avalanche-fuji.infura.io/v3/${INFURA_API_KEY}"

# GNOSIS CHAIN
gnosis_chain = "https://rpc.gnosischain.com"
18 changes: 10 additions & 8 deletions scripts/foundry/Base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@ abstract contract BaseScript is Script {
/// @dev Used to derive the broadcaster's address if $PRIVATE_KEY is not defined.
string internal mnemonic;

/// @dev The private key of the transaction broadcaster.
uint256 private broadcasterPK;

/// @dev Initializes the transaction broadcaster like this:
///
/// - If $PRIVATE_KEY is defined, use it.
/// - Otherwise, derive the broadcaster address from $MNEMONIC.
/// - If $MNEMONIC is not defined, default to a test mnemonic.
///
/// The use case for $PRIVATE_KEY is to specify the broadcaster key and its address via the
/// command line.
constructor() {
address from = vm.envOr({ name: "PRIVATE_KEY", defaultValue: address(0) });
if (from != address(0)) {
broadcaster = from;
uint256 privateKey = vm.envOr({ name: "PRIVATE_KEY", defaultValue: uint256(0) });

if (privateKey != 0) {
broadcaster = vm.addr(privateKey);
broadcasterPK = privateKey;
} else {
mnemonic = vm.envOr({ name: "MNEMONIC", defaultValue: TEST_MNEMONIC });
(broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
(broadcaster, broadcasterPK) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
}
}

modifier broadcast() {
vm.startBroadcast(broadcaster);
vm.startBroadcast(broadcasterPK);
_;
vm.stopBroadcast();
}
Expand Down

0 comments on commit a1a16a4

Please sign in to comment.