-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment.ts
69 lines (59 loc) · 2.69 KB
/
experiment.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
import { Tx } from "cosmjs-types/cosmos/tx/v1beta1/tx"
import { IndexedTx , SigningStargateClient , StargateClient } from "@cosmjs/stargate"
import { readFile } from "fs/promises"
import { DirectSecp256k1HdWallet , OfflineDirectSigner } from "@cosmjs/proto-signing"
import {
calculateFee,
} from "@cosmjs/stargate";
import { parse } from "papaparse";
import fs from "fs"
import csv from "csv-parser"
import iconv from "iconv-lite"
const getAliceSignerFromMnemonic = async ( ) : Promise < OfflineDirectSigner > => {
return DirectSecp256k1HdWallet . fromMnemonic ( ( await readFile ( "./testnet.alice.mnemonic.key" ) ) . toString ( ) , {
prefix : "sei" ,
} )
}
const rpc = 'https://sei-testnet-2-rpc.brocha.in/';
const runAll = async(): Promise<void> => {
const client = await StargateClient.connect(rpc)
// Check the balance of Alice and the Faucet
const aliceSigner: OfflineDirectSigner = await getAliceSignerFromMnemonic()
const signingClient = await SigningStargateClient.connectWithSigner(rpc, aliceSigner)
// const faucet: string = 'sei1vyx48apc22fefr99n4t3sdghtulwywzp6g8g0v'
const alice: string = 'sei1mrauz7fgzmj42nvfgz0n3pe8eurwnm3w9a7ves'
// Read CSV file
const results: any[] = [];
fs.createReadStream('./test10000.csv')
.pipe(iconv.decodeStream('utf-8'))
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', async () => {
// Loop through each row in the CSV file
// console.log(results)
for (const row of results) {
const faucet = row.public;
const key = row.private;
// Check the balance of Alice and the Faucet
const aliceSigner: OfflineDirectSigner = await getAliceSignerFromMnemonic()
const signingClient = await SigningStargateClient.connectWithSigner(rpc, aliceSigner)
// console.log("Alice balance before:", await client.getAllBalances(alice))
// console.log("Faucet balance before:", await client.getAllBalances(faucet))
// console.log(alice)
// console.log(faucet)
const fee = calculateFee(500000, "0.1usei");
// Execute the sendTokens Tx and store the result
const result = await signingClient.sendTokens(
alice,
faucet,
[{ denom: 'usei', amount: "100000" }],
fee
)
// Output the result of the Tx
console.log("Transfer result:", result)
// console.log("Alice balance after:", await client.getAllBalances(alice))
// console.log("Faucet balance after:", await client.getAllBalances(faucet))
}
});
}
runAll()