Skip to content

Commit ee4652b

Browse files
committed
refactor: remove chain-id input and detect it from RPC URL in workflow
1 parent a5e6179 commit ee4652b

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

β€Ž.github/workflows/safe-transaction.ymlβ€Ž

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ on:
66
description: 'RPC URL for the blockchain network'
77
required: true
88
type: string
9-
chain-id:
10-
description: 'Chain ID of the blockchain network (default: 42161 for Arbitrum)'
11-
required: false
12-
default: '42161'
13-
type: string
149
safe-address:
1510
description: 'Address of the Safe contract'
1611
required: true
@@ -81,7 +76,6 @@ jobs:
8176
INPUT_RPC_URL: ${{ inputs.rpc-url }}
8277
INPUT_SAFE_ADDRESS: ${{ inputs.safe-address }}
8378
INPUT_TRANSACTION_TO: ${{ inputs.transaction-to }}
84-
INPUT_CHAIN_ID: ${{ inputs.chain-id }}
8579
INPUT_TRANSACTION_VALUE: ${{ inputs.transaction-value }}
8680
INPUT_TRANSACTION_DATA: ${{ inputs.transaction-data }}
8781
id: safe-transaction

β€Žsafe-transaction/README.mdβ€Ž

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
This reusable GitHub Actions workflow automates the process of proposing transactions to a Safe multi-signature wallet (Gnosis Safe). It handles the proposal submission, making it easy to integrate Safe transactions into your CI/CD pipeline.
66

7+
**πŸ€– Smart Chain Detection**: The workflow automatically detects the blockchain network's Chain ID from the provided RPC URL, eliminating the need to manually specify it.
8+
79
## Workflow Inputs πŸ› οΈ
810

911
| **Input** | **Description** | **Required** | **Default** |
1012
| ------------------------ | ------------------------------------------------------------- | ------------ | ----------------------------------- |
1113
| **proposer-private-key** | Private key of the proposer wallet | Yes | - |
1214
| **rpc-url** | RPC URL for the blockchain network | Yes | - |
13-
| **chain-id** | Chain ID of the blockchain network | No | `42161` (Arbitrum) |
1415
| **safe-address** | Address of the Safe contract | Yes | - |
1516
| **transaction-to** | Target address for the transaction | Yes | - |
1617
| **safe-api-key** | Safe API key for transaction service | Yes | - |
@@ -47,10 +48,6 @@ This reusable GitHub Actions workflow automates the process of proposing transac
4748
transaction-to:
4849
description: 'Target contract address'
4950
required: true
50-
chain-id:
51-
description: 'Chain ID (e.g., 1 for Ethereum, 42161 for Arbitrum)'
52-
required: false
53-
default: '42161'
5451
transaction-data:
5552
description: 'Transaction data (0x prefixed)'
5653
required: false
@@ -66,7 +63,6 @@ This reusable GitHub Actions workflow automates the process of proposing transac
6663
with:
6764
safe-address: ${{ inputs.safe-address }}
6865
transaction-to: ${{ inputs.transaction-to }}
69-
chain-id: ${{ inputs.chain-id }}
7066
transaction-data: ${{ inputs.transaction-data }}
7167
```
7268

β€Žsafe-transaction/src/index.tsβ€Ž

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import * as core from '@actions/core';
22
import SafeApiKit from "@safe-global/api-kit";
33
import Safe from "@safe-global/protocol-kit";
44
import { OperationType, MetaTransactionData } from "@safe-global/types-kit";
5-
import { Wallet } from "ethers";
5+
import { Wallet, JsonRpcProvider } from "ethers";
66

77
async function run() {
88
try {
99
// Get inputs from environment variables
1010
const proposerPrivateKey = process.env.INPUT_PROPOSER_PRIVATE_KEY;
1111
const rpcUrl = process.env.INPUT_RPC_URL;
12-
const chainId = process.env.INPUT_CHAIN_ID || "42161"; // Default to Arbitrum
1312
const safeAddress = process.env.INPUT_SAFE_ADDRESS;
1413
const transactionTo = process.env.INPUT_TRANSACTION_TO;
1514
const safeApiKey = process.env.INPUT_SAFE_API_KEY;
@@ -28,14 +27,20 @@ async function run() {
2827
}
2928

3029
core.info(`πŸš€ Starting Safe transaction proposal...`);
31-
core.info(`🌐 Chain ID: ${chainId}`);
3230
core.info(`πŸ“ Safe Address: ${safeAddress}`);
3331
core.info(`🎯 Target Address: ${transactionTo}`);
3432

3533
// Initialize wallet
3634
const wallet = new Wallet(proposerPrivateKey);
3735
core.info(`πŸ”‘ Proposer Address: ${wallet.address}`);
3836

37+
// Detect chainId from RPC
38+
core.info(`πŸ” Detecting chain ID from RPC...`);
39+
const provider = new JsonRpcProvider(rpcUrl);
40+
const network = await provider.getNetwork();
41+
const chainId = network.chainId.toString();
42+
core.info(`🌐 Detected Chain ID: ${chainId}`);
43+
3944
// Initialize API Kit
4045
const apiKit = new SafeApiKit({
4146
chainId: BigInt(chainId),

0 commit comments

Comments
Β (0)