Skip to content

Commit 431dbe9

Browse files
committed
refactor: replace ethers with viem for wallet and chain ID detection
1 parent ee4652b commit 431dbe9

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

β€Žsafe-transaction/package.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@safe-global/api-kit": "^4.0.0",
1212
"@safe-global/protocol-kit": "^6.1.1",
1313
"@safe-global/types-kit": "^3.0.0",
14-
"ethers": "^6.15.0"
14+
"viem": "^2.21.0"
1515
},
1616
"devDependencies": {
1717
"typescript": "^5.0.0"

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ 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, JsonRpcProvider } from "ethers";
5+
import { createPublicClient, http } from "viem";
6+
import { privateKeyToAccount } from "viem/accounts";
67

78
async function run() {
89
try {
@@ -31,15 +32,16 @@ async function run() {
3132
core.info(`🎯 Target Address: ${transactionTo}`);
3233

3334
// Initialize wallet
34-
const wallet = new Wallet(proposerPrivateKey);
35-
core.info(`πŸ”‘ Proposer Address: ${wallet.address}`);
35+
const account = privateKeyToAccount(proposerPrivateKey as `0x${string}`);
36+
core.info(`πŸ”‘ Proposer Address: ${account.address}`);
3637

3738
// Detect chainId from RPC
3839
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}`);
40+
const publicClient = createPublicClient({
41+
transport: http(rpcUrl),
42+
});
43+
const chainId = await publicClient.getChainId();
44+
core.info(`🌐 Detected Chain ID: ${chainId.toString()}`);
4345

4446
// Initialize API Kit
4547
const apiKit = new SafeApiKit({
@@ -81,7 +83,7 @@ async function run() {
8183
safeAddress: safeAddress,
8284
safeTransactionData: safeTransaction.data,
8385
safeTxHash: safeTxHash,
84-
senderAddress: wallet.address,
86+
senderAddress: account.address,
8587
senderSignature: signature.data,
8688
origin: "GitHub Action - Safe Transaction",
8789
});

0 commit comments

Comments
Β (0)