This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from cosmostation/develop
Develop
- Loading branch information
Showing
8 changed files
with
71 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ This library supports cosmos address generation and verification. It enables you | |
|
||
[![MIT](https://img.shields.io/apm/l/vim-mode.svg)](https://github.com/cosmostation/cosmosjs/blob/master/LICENSE) | ||
[![NPM](https://img.shields.io/npm/v/@cosmostation/cosmosjs.svg)](https://www.npmjs.com/package/@cosmostation/cosmosjs) | ||
[![](https://data.jsdelivr.com/v1/package/npm/@cosmostation/cosmosjs/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@cosmostation/cosmosjs) | ||
|
||
## Installation | ||
|
||
|
@@ -52,13 +53,13 @@ const cosmosjs = require("@cosmostation/cosmosjs"); | |
- You can see example file at [/example/browser-example.html](https://github.com/cosmostation/cosmosjs/tree/master/example/browser-example.html) | ||
|
||
```js | ||
<script src="https://cdn.jsdelivr.net/npm/@cosmostation/[email protected].7/dist/cosmosjs-0.5.7.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@cosmostation/[email protected].8/dist/cosmos.js"></script> | ||
``` | ||
|
||
## Usage | ||
- Cosmos: Generate Cosmos address from mnemonic | ||
```js | ||
const cosmosjs = require("@cosmostation/cosmosjs"); | ||
const cosmosjs = require("@cosmostation/cosmosjs"); // only NodeJS | ||
|
||
const chainId = "cosmoshub-3"; | ||
const cosmos = cosmosjs.network(lcdUrl, chainId); | ||
|
@@ -70,15 +71,15 @@ const ecpairPriv = cosmos.getECPairPriv(mnemonic); | |
``` | ||
- Iris | ||
```js | ||
const cosmosjs = require("@cosmostation/cosmosjs"); | ||
const cosmosjs = require("@cosmostation/cosmosjs"); // only NodeJS | ||
|
||
const chainId = "irishub"; | ||
const iris = cosmosjs.network(lcdUrl, chainId); | ||
iris.setBech32MainPrefix("iaa"); | ||
``` | ||
- Kava | ||
```js | ||
const cosmosjs = require("@cosmostation/cosmosjs"); | ||
const cosmosjs = require("@cosmostation/cosmosjs"); // only NodeJS | ||
|
||
const chainId = "kava-2"; | ||
const kava = cosmosjs.network(lcdUrl, chainId); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
<title>CosmosJS Example</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script src="https://cdn.jsdelivr.net/npm/@cosmostation/[email protected].7/dist/cosmosjs-0.5.7.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@cosmostation/[email protected].8/dist/cosmos.js"></script> | ||
<script> | ||
function load() { | ||
const mnemonic = "swear buyer security impulse public stereo peasant correct cross tornado bid discover anchor float venture deal patch property cool wreck eight dwarf december surface"; | ||
|
@@ -19,6 +19,7 @@ | |
console.log("myAddress: ", address); | ||
document.getElementById('myAddress').innerHTML = "[myAddress]<br>" + address; | ||
|
||
// You can send ATOM by running the code below. | ||
/* | ||
cosmos.getAccounts(address).then(data => { | ||
let stdSignMsg = cosmos.newStdMsg({ | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const cosmosjs = require("../src"); | ||
|
||
const mnemonic = "YOUR MNEMONIC"; | ||
const chainId = "kava-testnet-6000"; | ||
const kava = cosmosjs.network("PUBLIC REST SERVER ENDPOINT", chainId); | ||
kava.setBech32MainPrefix("kava"); // same prefix as Mainnet | ||
kava.setPath("m/44'/459'/0'/0/0"); // old derivation path: m/44'/118'/0'/0/0 | ||
const address = kava.getAddress(mnemonic); | ||
const ecpairPriv = kava.getECPairPriv(mnemonic); | ||
|
||
// Testnet faucet URL: https://faucet.kava.io/ | ||
|
||
// Generate MsgDeposit transaction and broadcast | ||
kava.getAccounts(address).then(data => { | ||
let stdSignMsg = kava.newStdMsg({ | ||
msgs: [ | ||
{ | ||
type: "cdp/MsgDeposit", | ||
value: { | ||
owner: "CDP OWNDER ADDRESS", | ||
depositor: address, | ||
collateral: [ | ||
{ | ||
denom: "btc", | ||
amount: "1500" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
chain_id: chainId, | ||
fee: { | ||
amount: [{ amount: String(5000), denom: "ukava" }], | ||
gas: String(200000) | ||
}, | ||
memo: "Test transaction using CosmosJS by Cosmostation", | ||
account_number: String(data.result.value.account_number), | ||
sequence: String(data.result.value.sequence) | ||
}); | ||
|
||
const signedTx = kava.sign(stdSignMsg, ecpairPriv); | ||
kava.broadcast(signedTx).then(response => console.log(response)); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters