diff --git a/package.json b/package.json index f923ea30a5..fb1a63a556 100644 --- a/package.json +++ b/package.json @@ -53,8 +53,8 @@ "// Build and zip": "", "bundle": "yarn build && yarn zip", "// Runs tests": "", - "anvil": "ETH_MAINNET_RPC=$(grep ETH_MAINNET_RPC .env | cut -d '=' -f2) && anvil --fork-url $ETH_MAINNET_RPC", - "anvil:optimism": "OPTIMISM_MAINNET_RPC=$(grep OPTIMISM_MAINNET_RPC .env | cut -d '=' -f2) && anvil --fork-url $OPTIMISM_MAINNET_RPC", + "anvil": "anvil --fork-url $(./scripts/get-rpc-url.sh mainnet)", + "anvil:optimism": "anvil --fork-url $(./scripts/get-rpc-url.sh optimism)", "anvil:kill": "lsof -i :8545|tail -n +2|awk '{print $2}'|xargs -r kill -s SIGINT", "test": "./scripts/unit-tests.sh", "test:watch": "yarn anvil & vitest --watch", diff --git a/scripts/get-rpc-url.sh b/scripts/get-rpc-url.sh new file mode 100755 index 0000000000..a45aeed504 --- /dev/null +++ b/scripts/get-rpc-url.sh @@ -0,0 +1,12 @@ +#!/bin/bash +NETWORK=$1 +KEY=$(grep ALCHEMY_DEV_KEY .env | cut -d '=' -f2) + +case $NETWORK in + "optimism") + echo "https://opt-mainnet.g.alchemy.com/v2/$KEY" + ;; + "mainnet") + echo "https://eth-mainnet.g.alchemy.com/v2/$KEY" + ;; +esac \ No newline at end of file