-
Notifications
You must be signed in to change notification settings - Fork 2
/
increment-counter.ts
94 lines (67 loc) · 2.05 KB
/
increment-counter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { ethers } from "ethers";
// import { GelatoRelayPack } from "gelato-relay-kit";
import Safe, {
EthersAdapter,
getSafeContract,
} from "gelato-raas-protocol-kit";
import {
MetaTransactionData,
OperationType,
} from "@safe-global/safe-core-sdk-types";
import * as dotenv from "dotenv";
dotenv.config({ path: ".env" });
import ContractInfo from "../../deployments/opTest/SimpleCounter.json";
let RPC_URL = "https://rpc.op-testnet.gelato.digital";
const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const signer = new ethers.Wallet(process.env.PK!, provider);
let safeAddress = "0xf35EAc5DA7d808264a9c7B1C19E2946201320522";
const targetAddress = ContractInfo.address;
const nftContract = new ethers.Contract(
targetAddress,
ContractInfo.abi,
signer
);
async function incrementCounter() {
const ethAdapter = new EthersAdapter({
ethers,
signerOrProvider: signer,
});
const safeSDK = await Safe.create({
ethAdapter,
safeAddress,
});
const safeTransactionData: MetaTransactionData = {
to: targetAddress,
data: nftContract.interface.encodeFunctionData("increment", []),
value: "0",
operation: OperationType.Call,
};
const standardizedSafeTx = await safeSDK.createTransaction({
safeTransactionData,
});
const safeSingletonContract = await getSafeContract({
ethAdapter: ethAdapter,
safeVersion: await safeSDK.getContractVersion(),
});
const signedSafeTx = await safeSDK.signTransaction(standardizedSafeTx);
const encodedTx = safeSingletonContract.encode("execTransaction", [
signedSafeTx.data.to,
signedSafeTx.data.value,
signedSafeTx.data.data,
signedSafeTx.data.operation,
signedSafeTx.data.safeTxGas,
signedSafeTx.data.baseGas,
signedSafeTx.data.gasPrice,
signedSafeTx.data.gasToken,
signedSafeTx.data.refundReceiver,
signedSafeTx.encodedSignatures(),
]);
let tx = await signer.sendTransaction({
value: 0,
to: safeAddress,
data: encodedTx,
});
await tx.wait();
console.log('TxHash: ',tx.hash)
}
incrementCounter();