-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (25 loc) · 876 Bytes
/
index.js
File metadata and controls
32 lines (25 loc) · 876 Bytes
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
import ethers from 'ethers';
const contractAddress = process.env.CONTRACT_ADDRESS;
const abi = [
'function counter() view returns (uint256)',
'function increment()'
];
const mumbai = {
name: 'mumbai',
chainId: 80001,
_defaultProvider: (providers) =>
new providers.JsonRpcProvider('https://matic-mumbai.chainstacklabs.com')
};
const provider = ethers.getDefaultProvider(mumbai);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
const counterContract = new ethers.Contract(contractAddress, abi, provider);
const counter = counterContract.connect(wallet);
const increment = async () => {
console.log('🤖 Incrementing counter...');
// Just call the method...
const tx = await counter.increment();
await tx.wait();
const value = await counterContract.counter();
console.log(`✅ Done. New value is ${value}`);
};
increment();