forked from mattmasteller/waveportal-web3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.mjs
45 lines (35 loc) · 1.13 KB
/
test.mjs
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
import { ethers } from 'ethers'
import 'dotenv/config'
/*
Experimental JSON import is behind a flag
$ node test.mjs # doesn't work
$ node --experimental-json-modules test.mjs #works
*/
import abi from './utils/WavePortal.json'
const providerUrl = process.env.NETWORK_URL
const contractAddress = process.env.CONTRACT_ADDRESS
const contractABI = abi.abi
const getNumberOfWaves = async () => {
const provider = new ethers.providers.JsonRpcProvider(providerUrl)
const wavePortalContract = new ethers.Contract(
contractAddress,
contractABI,
provider
)
const count = await wavePortalContract.getTotalWaves()
console.log(count.toNumber())
}
const getAllWaves = async () => {
const provider = new ethers.providers.JsonRpcProvider(providerUrl)
const contract = new ethers.Contract(contractAddress, contractABI, provider)
const waves = await contract.getAllWaves()
console.log('Retrieved all waves...', waves)
return waves.map((w) => ({
address: w.waver,
timestamp: new Date(w.timestamp * 1000),
message: w.message,
}))
}
await getNumberOfWaves()
const waves = await getAllWaves()
console.log('waves', waves)