-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (40 loc) · 1.74 KB
/
index.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
import type { EncodeObject } from "@cosmjs/proto-signing";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice, SigningStargateClient } from "@cosmjs/stargate";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
const addresses = {
griko_nibras: `cosmos1kpzxx2lxg05xxn8mfygrerhmkj0ypn8edmu2pu`,
kikiding: `cosmos1g3jjhgkyf36pjhe7u5cw8j9u6cgl8x929ej430`,
asaadam: `cosmos1q7u2wv5rmzphm53cww42ydcrsgjp7he8u3f85f`,
};
const run = async () => {
// https://github.com/cosmos/chain-registry/blob/master/cosmoshub/chain.json
const chainId = "cosmoshub-4";
const rpcEndpoint = "https://rpc.cosmos.directory/cosmoshub";
const bech32Prefix = "cosmos";
const mnemonic = process.env.MNEMONIC || raise("configure mnemonic in .env file");
const offlineSigner = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: bech32Prefix });
const accounts = await offlineSigner.getAccounts();
const account = accounts[0] || raise("no account found");
const signingClient = await SigningStargateClient.connectWithSigner(rpcEndpoint, offlineSigner, {
gasPrice: GasPrice.fromString("0.025uatom"),
});
const sendTokenPayload = MsgSend.fromPartial({
fromAddress: account.address,
toAddress: addresses.griko_nibras,
amount: [{ amount: "10000", denom: "uatom" }],
});
const encodedSendTokenPayload = MsgSend.encode(sendTokenPayload).finish();
const messagesToSend: EncodeObject[] = [
{
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: encodedSendTokenPayload,
},
];
const response = await signingClient.signAndBroadcast(account.address, messagesToSend, "auto");
console.log(response);
};
const raise = (message?: string): never => {
throw new Error(message);
};
void run();