How to use keystore wallet in the code? #1481
Replies: 2 comments
-
Hello @Charlie-Mack , i did use |
Beta Was this translation helpful? Give feedback.
-
I was able to use encrypted private keys in code for a different lesson. You could use some of the techniques here and see if it works for you Had to refactor
Store the path to your encrypted key in your
contract HelperConfig is Script {
NetworkConfig public activeNetworkConfig;
NetworkConfigSepolia public activeNetworkConfigSepolia; // 1
/*SNIPPED*/
struct NetworkConfig {/*Specifically for Anvil*/
address wethUsdPriceFeed;
address wbtcUsdPriceFeed;
address weth;
address wbtc;
uint256 deployerKey;
}
struct NetworkConfigSepolia { /*Specifically for Sepolia*/
address wethUsdPriceFeed;
address wbtcUsdPriceFeed;
address weth;
address wbtc;
@> string deployerKey;
}
/*SNIPPED*/
constructor() {
if (block.chainid == 11155111) {
@> activeNetworkConfigSepolia = getSepoliaEthConfig();
} else {
activeNetworkConfig = getOrCreateAnvilEthConfig();
}
}
function getSepoliaEthConfig() public view returns (NetworkConfigSepolia memory sepoliaNetworkConfig) {
@> sepoliaNetworkConfig = NetworkConfigSepolia ({
wethUsdPriceFeed: 0x694AA1769357215DE4FAC081bf1f309aDC325306, // ETH / USD https://docs.chain.link/data-feeds/price-feeds/addresses?network=ethereum&page=1
wbtcUsdPriceFeed: 0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43, // BTC / USD https://docs.chain.link/data-feeds/price-feeds/addresses?network=ethereum&page=1
weth: 0xdd13E55209Fd76AfE204dBda4007C227904f0a81,
wbtc: 0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063, // Collateral token address gotten from?
@> deployerKey: vm.envString("ETH_KEYSTORE_ACCOUNT") // Reads encrypted SEPOLIA_PRIVATE_KEY path from .env file. **PRIVATE STUFF!**
});
}
function run() external returns (DecentralisedStableCoin, DSCEngine, HelperConfig) {
HelperConfig helperConfig = new HelperConfig(); // This comes with our mocks!
@> (address wethUsdPriceFeedSepolia, address wbtcUsdPriceFeedSepolia, address wethSepolia, address wbtcSepolia, /*uint256*/string memory deployerKeySepolia) =
helperConfig.activeNetworkConfigSepolia(); // For Sepolia
(address wethUsdPriceFeed, address wbtcUsdPriceFeed, address weth, address wbtc, uint256 deployerKey) =
helperConfig.activeNetworkConfig(); // For Anvil
tokenAddresses = [weth, wbtc]; //setting token[] for dscEngine constructor
priceFeedAddresses = [wethUsdPriceFeed, wbtcUsdPriceFeed]; //setting priceFeedAddress[] for dscEngine constructor sequentially for each corresponding token in tokenAddresses[]
@> vm.startBroadcast();
// Powering up each of the contracts
DecentralisedStableCoin dsc = new DecentralisedStableCoin();
DSCEngine dscEngine = new DSCEngine(tokenAddresses, priceFeedAddresses, address(dsc));
dsc.transferOwnership(address(dscEngine));
vm.stopBroadcast();
return (dsc, dscEngine, helperConfig);
}
Deploy with Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Hey Everyone.
I created myself a keystore to use in my cli commands using:
cast wallet import main --interactive
I can use this like so:
forge script script/DeployFunWithStorage.s.sol --rpc-url $RPC_URL --broadcast --account main
This works great because I don't have to expose my private key.
I am going through Lesson 9 now where you have to use a private key within the broadcast when adding the consumer. Is is possible to use keystore in the code or do I need to use a .env file?
Beta Was this translation helpful? Give feedback.
All reactions