-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalice_send_to_bob.ts
43 lines (33 loc) · 1.52 KB
/
alice_send_to_bob.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
import { StargateClient, SigningStargateClient } from "@cosmjs/stargate"
import { DirectSecp256k1HdWallet, OfflineDirectSigner } from "@cosmjs/proto-signing"
import alice from './knowledge_alice.json'
import config from './config.json'
const getAliceSignerFromMnemonic = async (): Promise<OfflineDirectSigner> => {
return DirectSecp256k1HdWallet.fromMnemonic(alice.my_mnemonic, {
prefix: "cosmos",
})
}
const runSendToBob = async(): Promise<void> => {
const client = await StargateClient.connect(config.rpc)
const aliceSigner: OfflineDirectSigner = await getAliceSignerFromMnemonic()
const alice_address = (await aliceSigner.getAccounts())[0].address
const signingClient = await SigningStargateClient.connectWithSigner(config.rpc, aliceSigner)
console.log("Bob balance before:", await signingClient.getAllBalances(alice.bob_address))
console.log("Alice balance before:", await client.getAllBalances(alice_address))
// Alice sends back 0.5 $ATOM to Bob
const result = await signingClient.sendTokens(
alice_address,
alice.bob_address,
[{ denom: "uatom", amount: "500000" }],
{
amount: [{ denom: "uatom", amount: "500" }],
gas: "200000",
},
"thank you!"
)
// Output the result of the Tx
console.log("Transfer result:", result)
console.log("Bob balance after:", await client.getAllBalances(alice.bob_address))
console.log("Alice balance after:", await client.getAllBalances(alice_address))
}
runSendToBob()