-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdecodeTx.ts
More file actions
42 lines (32 loc) · 1.12 KB
/
decodeTx.ts
File metadata and controls
42 lines (32 loc) · 1.12 KB
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
import { LCDClient, MsgSend, MnemonicKey } from '../src';
async function main() {
// create a key out of a mnemonic
const mk = new MnemonicKey({
mnemonic:
'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius',
});
const client = new LCDClient({
chainID: 'localterra',
URL: 'http://localhost:1317',
});
// a wallet can be created out of any key
// wallets abstract transaction building
const wallet = client.wallet(mk);
// create a simple message that moves coin balances
const send = new MsgSend(
'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
'terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp',
{ uluna: 1312029 }
);
const tx = await wallet
.createAndSignTx({
msgs: [send],
memo: 'decode test',
});
const encoded = client.tx.encode(tx);
const decoded = client.tx.decode(encoded);
console.log(`\n\tstringified:${JSON.stringify(tx)}`);
console.log(`\n\tencoded:${encoded}`);
console.log(`\n\tdecoded:${JSON.stringify(decoded)}`);
}
main().catch(console.error);