Add address generator example
This commit is contained in:
parent
0b5b4d569e
commit
736b27afaa
@ -75,6 +75,17 @@ const signedTx: types.StdTx = {
|
||||
const postResult = await client.postTx(marshalTx(signedTx));
|
||||
```
|
||||
|
||||
## Other example codes
|
||||
|
||||
### Create random mnemonic and Cosmos address
|
||||
|
||||
```ts
|
||||
const mnemonic = Bip39.encode(Random.getBytes(16)).toString();
|
||||
const pen = await Secp256k1Pen.fromMnemonic(mnemonic);
|
||||
const pubkey = encodeSecp256k1Pubkey(pen.pubkey);
|
||||
const address = encodeAddress(pubkey, "cosmos");
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This package is part of the cosmwasm-js repository, licensed under the Apache
|
||||
|
||||
8
packages/cli/examples/generate_address.ts
Normal file
8
packages/cli/examples/generate_address.ts
Normal file
@ -0,0 +1,8 @@
|
||||
const mnemonic = Bip39.encode(Random.getBytes(16)).toString();
|
||||
const pen = await Secp256k1Pen.fromMnemonic(mnemonic);
|
||||
const pubkey = encodeSecp256k1Pubkey(pen.pubkey);
|
||||
const address = encodeAddress(pubkey, "cosmos");
|
||||
|
||||
console.info("mnemonic:", mnemonic);
|
||||
console.info("pubkey:", pubkey);
|
||||
console.info("address:", address);
|
||||
Loading…
Reference in New Issue
Block a user