Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
get chain-id automatically in deploy-ipc (#184)
Browse files Browse the repository at this point in the history
* get chain-id automatically in deploy-ipc

* IPC-184: check if chain-id is valid
  • Loading branch information
adlrocha authored Aug 8, 2023
1 parent cc109a5 commit c986c1e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ==============================================================================
# Deployment

NETWORK ?= localnet
NETWORK ?= auto
OUTPUT ?= ./out

deploy-ipc:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ To deploy the IPC Solidity contracts in an FEVM network, you can directly run th
```bash
make deploy-ipc
```
The scripts run by `make` make use of hardhat under the hood. The default network for the deployment is `localnet` as configured in `hardhat.config.ts`.
The scripts run by `make` make use of hardhat under the hood. If no network has been configured, the script will automatically try to fetch the chainID of the target network, and perform the deployment according to the configuration in `hardhat.config.ts`.
To deploy the contracts in some other network configured in the Hardhat config you can run the following:
```bash
make deploy-ipc NETWORK=<network-name>
Expand Down
10 changes: 9 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ task('deploy-sa-diamond-and-facets', 'Builds and deploys Subnet Actor diamond an
const network = hre.network.name;
const deployments = await getDeployments(network);
const { deployDiamond } = await lazyImport('./scripts/deploy-sa-diamond');
const subnetActorDiamond = await deployDiamond(deployments.GatewayActorDiamond,deployments.libs);
const subnetActorDiamond = await deployDiamond(deployments.GatewayActorDiamond, deployments.libs);
console.log(subnetActorDiamond);
await saveDeployments(network, subnetActorDiamond);
});
Expand Down Expand Up @@ -136,6 +136,14 @@ const config: HardhatUserConfig = {
chainId: 31415926,
url: process.env.RPC_URL!,
accounts: [process.env.PRIVATE_KEY!],
},
// automatically fetch chainID for network
auto: {
chainId: parseInt(process.env.CHAIN_ID!, 16),
url: process.env.RPC_URL!,
accounts: [process.env.PRIVATE_KEY!],
// timeout to support also slow networks (like calibration/mainnet)
timeout: 1000000,
}
},
solidity: {
Expand Down
29 changes: 29 additions & 0 deletions ops/chain-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Check if RPC_URL is set
if [[ -z "$RPC_URL" ]]; then
echo "RPC_URL is not set. Sourcing .env file..."
source .env
fi

# Make a JSON-RPC call to get the chain ID using curl
response=$(curl -s -X POST -H "Content-Type: application/json" --data '{
"jsonrpc":"2.0",
"method":"eth_chainId",
"params":[],
"id":1
}' $RPC_URL)

# Extract the chain ID from the response using jq (ensure jq is installed)
chain_id=$(echo $response | jq -r '.result')

# Double-check that this is a valid chain-id
if [[ "$chain_id" =~ ^0x[0-9a-fA-F]+$ ]]; then
# Export the chain ID as an environmental variable
export CHAIN_ID=$chain_id
# Print the chain ID for verification (optional)
echo "[*] Target network Chain ID: $CHAIN_ID"
else
echo "[*] Error getting a valid hexadecimal chain ID"
exit 1
fi
5 changes: 5 additions & 0 deletions ops/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ LIB_OUTPUT="libraries.out"
GATEWAY_OUTPUT="gateway.out"
NETWORK=$1

if [ "$NETWORK" = "auto" ]; then
echo "[*] Automatically getting chainID for network"
source ops/chain-id.sh
fi

echo "[*] Deploying libraries"
(npx hardhat deploy-libraries --network ${NETWORK} | sed -n '/{/,/}/p') > scripts/${LIB_OUTPUT}
echo "const LIBMAP =" | cat - scripts/${LIB_OUTPUT} > temp && mv temp scripts/${LIB_OUTPUT}
Expand Down
2 changes: 2 additions & 0 deletions scripts/deploy-gateway.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export async function deploy(libs: { [key in string]: string }) {
chainId = 314159;
} else if (process.env.NETWORK == "mainnet") {
chainId = 314;
} else if (process.env.NETWORK == "auto") {
chainId = parseInt(process.env.CHAIN_ID!, 16);
}

await hre.run('compile');
Expand Down

0 comments on commit c986c1e

Please sign in to comment.