Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #48 from cosmostation/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Booyoun authored Jun 3, 2020
2 parents caa7aab + a536f3c commit 475991c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 26 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion dist/cosmosjs-0.5.7.js → dist/cosmos.js
Original file line number Diff line number Diff line change
Expand Up @@ -34447,7 +34447,7 @@ Cosmos.prototype.newStdMsg = function(input) {
}

Cosmos.prototype.sign = function(stdSignMsg, ecpairPriv, modeType = "sync") {
// The supported return types includes "block"(return after tx commit), "sync"(return afer CheckTx) and "async"(return right away).
// The supported return types includes "block"(return after tx commit), "sync"(return after CheckTx) and "async"(return right away).
let signMessage = new Object;
if (stdSignMsg.json.msgs[0].type == "irishub/bank/Send" ||
stdSignMsg.json.msgs[0].type == "irishub/stake/BeginUnbonding" ||
Expand Down
38 changes: 19 additions & 19 deletions docs/msg_types/kava.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Kava is a collateralized debt position built on top of Cosmos SDK. It has pretty

```js
// cosmos-sdk/MsgSend
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgSend",
Expand Down Expand Up @@ -62,7 +62,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgMultiSend
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgMultiSend",
Expand Down Expand Up @@ -104,7 +104,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgCreateValidator
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgCreateValidator",
Expand Down Expand Up @@ -143,7 +143,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgEditValidator
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgEditValidator",
Expand Down Expand Up @@ -172,7 +172,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgDelegate
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgDelegate",
Expand All @@ -198,7 +198,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgUndelegate
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgUndelegate",
Expand All @@ -224,7 +224,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgBeginRedelegate
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgBeginRedelegate",
Expand All @@ -251,7 +251,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgWithdrawDelegationReward
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgWithdrawDelegationReward",
Expand All @@ -273,7 +273,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgWithdrawValidatorCommission
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgWithdrawValidatorCommission",
Expand All @@ -294,7 +294,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgModifyWithdrawAddress
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgModifyWithdrawAddress",
Expand All @@ -316,7 +316,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgSubmitProposal
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgSubmitProposal",
Expand Down Expand Up @@ -346,7 +346,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgDeposit
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgDeposit",
Expand Down Expand Up @@ -374,7 +374,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgVote
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgVote",
Expand All @@ -397,7 +397,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cosmos-sdk/MsgUnjail
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cosmos-sdk/MsgUnjail",
Expand All @@ -418,7 +418,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cdp/MsgCreateCDP
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cdp/MsgCreateCDP",
Expand Down Expand Up @@ -450,7 +450,7 @@ let stdSignMsg = cosmos.newStdMsg({
### MsgDeposit
```js
// cdp/MsgDeposit
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cdp/MsgDeposit",
Expand Down Expand Up @@ -478,7 +478,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cdp/MsgWithdraw
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cdp/MsgWithdraw",
Expand Down Expand Up @@ -506,7 +506,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cdp/MsgDrawDebt
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cdp/MsgDrawDebt",
Expand Down Expand Up @@ -534,7 +534,7 @@ let stdSignMsg = cosmos.newStdMsg({

```js
// cdp/MsgRepayDebt
let stdSignMsg = cosmos.newStdMsg({
let stdSignMsg = kava.newStdMsg({
msgs: [
{
type: "cdp/MsgRepayDebt",
Expand Down
3 changes: 2 additions & 1 deletion example/browser-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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({
Expand Down
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions example/kava-testnet-6000.js
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));
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cosmostation/cosmosjs",
"version": "0.5.7",
"version": "0.5.8",
"description": "A JavasSript Open Source Library for Cosmos Network, IRISnet, and Kava",
"main": "./src/index.js",
"repository": {
Expand Down

0 comments on commit 475991c

Please sign in to comment.