From ba13592e181d47bddba9ad46280e33bb0ca2bea7 Mon Sep 17 00:00:00 2001 From: Booyoun-Kim Date: Tue, 6 Oct 2020 11:33:39 +0900 Subject: [PATCH] Remove rest server URLs. Added Secret Network. --- README.md | 4 +- docs/msg_types/scrt.md | 406 +++++++++++++++++++++++++++++++++++ example/band-protocol.js | 3 +- example/browser-example.html | 2 + example/cosmoshub.js | 2 + example/iov.js | 3 +- example/irishub.js | 3 +- example/kava.js | 3 +- example/scrt.js | 40 ++++ package.json | 9 +- 10 files changed, 467 insertions(+), 8 deletions(-) create mode 100644 docs/msg_types/scrt.md create mode 100644 example/scrt.js diff --git a/README.md b/README.md index 72c6dd2..05ba4ce 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,9 @@ cosmos.broadcast(signedTx).then(response => console.log(response)); ``` Cosmostation offers LCD url([https://lcd-cosmos-free.cosmostation.io](https://lcd-cosmos-free.cosmostation.io/node_info)). -* API Rate Limiting: 10 requests per second +- This rest server URL may be disabled at any time. In order to maintain stable blockchain service, it is recommended to prepare your rest server. +- Setting up the rest server: (https://hub.cosmos.network/master/resources/service-providers.html#setting-up-the-rest-server) +- API Rate Limiting: 2 requests per second ## Supporting Message Types (Updating...) - If you need more message types, you can see [/docs/msg_types](https://github.com/cosmostation/cosmosjs/tree/master/docs/msg_types) diff --git a/docs/msg_types/scrt.md b/docs/msg_types/scrt.md new file mode 100644 index 0000000..28785a4 --- /dev/null +++ b/docs/msg_types/scrt.md @@ -0,0 +1,406 @@ +# Secret Network + +In this docs, these are supporting message types in SCRT. + +Secret Network is the first blockchain to allow privacy-preserving smart contracts. + +### Supporting Message Types + +- [cosmos-sdk/MsgSend](#msgsend) +- [cosmos-sdk/MsgMultiSend](#msgmultisend) +- [cosmos-sdk/MsgCreateValidator](#msgcreatevalidator) +- [cosmos-sdk/MsgEditValidator](#msgeditvalidator) +- [cosmos-sdk/MsgDelegate](#msgdelegate) +- [cosmos-sdk/MsgUndelegate](#msgundelegate) +- [cosmos-sdk/MsgBeginRedelegate](#msgbeginredelegate) +- [cosmos-sdk/MsgWithdrawDelegationReward](#msgwithdrawdelegationreward) +- [cosmos-sdk/MsgWithdrawValidatorCommission](#msgwithdrawvalidatorcommission) +- [cosmos-sdk/MsgModifyWithdrawAddress](#msgmodifywithdrawaddress) +- [cosmos-sdk/MsgSubmitProposal](#msgsubmitproposal) +- [cosmos-sdk/MsgDeposit](#msgdeposit) +- [cosmos-sdk/MsgVote](#msgvote) +- [cosmos-sdk/MsgUnjail](#msgunjail) + +### MsgSend + +```js +// cosmos-sdk/MsgSend +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgSend", + value: { + amount: [ + { + amount: String(100000), // 6 decimal places (1000000 uscrt = 1 SCRT) + denom: "uscrt" + } + ], + from_address: address, + to_address: "secret1quxn7c79z5vd85wzzpt4cxh0xcqyrl7fphcgx3" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgMultiSend + +```js +// cosmos-sdk/MsgMultiSend +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgMultiSend", + value: { + inputs: [ + { + address: address, + coins: [ + { + amount: String(100000), // 6 decimal places (1000000 uscrt = 1 SCRT) + denom: "uscrt" + } + ] + } + ], + outputs: [ + { + address: "secret1quxn7c79z5vd85wzzpt4cxh0xcqyrl7fphcgx3", + coins: [ + { + amount: String(100000), + denom: "uscrt" + } + ] + } + ] + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgCreateValidator + +```js +// cosmos-sdk/MsgCreateValidator +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgCreateValidator", + value: { + description: { + moniker: "Test Validator", + identity: "", + website: "", + details: "" + }, + commission: { + rate: "0.250000000000000000", // 25.0% + max_rate: "1.000000000000000000", + max_change_rate: "0.100000000000000000" + }, + min_self_delegation: String(1), + delegator_address: address, + validator_address: "secretvaloper1hscf4cjrhzsea5an5smt4z9aezhh4sf5jjrqka", + pubkey: "secretpub1addwnpepqw5k9p439nw0zpg2aundx4umwx4nw233z5prpjqjv5anl5grmnchzp2xwvv", + value: { + denom: "uscrt", + amount: String(1) + } + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgEditValidator + +```js +// cosmos-sdk/MsgEditValidator +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgEditValidator", + value: { + Description: { + moniker: "Best Validator", + identity: "[do-not-modify]", + website: "[do-not-modify]", + details: "[do-not-modify]" + }, + address: "secretvaloper1hscf4cjrhzsea5an5smt4z9aezhh4sf5jjrqka", + commission_rate: "0.220000000000000000", // 22.0% + min_self_delegation: null + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgDelegate + +```js +// cosmos-sdk/MsgDelegate +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgDelegate", + value: { + amount: { + amount: String(1000000), + denom: "uscrt" + }, + delegator_address: address, + validator_address: "secretvaloper1hscf4cjrhzsea5an5smt4z9aezhh4sf5jjrqka" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgUndelegate + +```js +// cosmos-sdk/MsgUndelegate +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgUndelegate", + value: { + amount: { + amount: String(1000000), + denom: "uscrt" + }, + delegator_address: address, + validator_address: "secretvaloper1hscf4cjrhzsea5an5smt4z9aezhh4sf5jjrqka" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgBeginRedelegate + +```js +// cosmos-sdk/MsgBeginRedelegate +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgBeginRedelegate", + value: { + amount: { + amount: String(1000000), + denom: "uscrt" + }, + delegator_address: address, + validator_dst_address: "secretvaloper1hscf4cjrhzsea5an5smt4z9aezhh4sf5jjrqka", + validator_src_address: "secretvaloper1hjd20hjvkx06y8p42xl0uzr3gr3ue3nkvd79jj" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgWithdrawDelegationReward + +```js +// cosmos-sdk/MsgWithdrawDelegationReward +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgWithdrawDelegationReward", + value: { + delegator_address: address, + validator_address: "secretvaloper1hscf4cjrhzsea5an5smt4z9aezhh4sf5jjrqka" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgWithdrawValidatorCommission + +```js +// cosmos-sdk/MsgWithdrawValidatorCommission +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgWithdrawValidatorCommission", + value: { + validator_address: "secretvaloper1hscf4cjrhzsea5an5smt4z9aezhh4sf5jjrqka" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgModifyWithdrawAddress + +```js +// cosmos-sdk/MsgModifyWithdrawAddress +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgModifyWithdrawAddress", + value: { + delegator_address: address, + withdraw_address: "secret1quxn7c79z5vd85wzzpt4cxh0xcqyrl7fphcgx3" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgSubmitProposal + +```js +// cosmos-sdk/MsgSubmitProposal +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgSubmitProposal", + value: { + title: "Activate the Community Pool", + description: "Enable governance to spend funds from the community pool. Full proposal: https://ipfs.io/ipfs/QmNsVCsyRmEiep8rTQLxVNdMHm2uiZkmaSHCR6S72Y1sL1", + initial_deposit: [ + { + amount: String(1000000), + denom: "uscrt" + } + ], + proposal_type: "Text", + proposer: address + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgDeposit + +```js +// cosmos-sdk/MsgDeposit +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgDeposit", + value: { + amount: [ + { + amount: String(1000000), + denom: "uscrt" + } + ], + depositor: address, + proposal_id: String(1) + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgVote + +```js +// cosmos-sdk/MsgVote +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgVote", + value: { + option: "Yes", // Yes, No, NowithVeto, Abstain + proposal_id: String(1), + voter: address + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` + +### MsgUnjail + +```js +// cosmos-sdk/MsgUnjail +let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgUnjail", + value: { + address: "secretvaloper1hjd20hjvkx06y8p42xl0uzr3gr3ue3nkvd79jj" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) +}); +``` diff --git a/example/band-protocol.js b/example/band-protocol.js index 1506ed7..75c09d3 100644 --- a/example/band-protocol.js +++ b/example/band-protocol.js @@ -3,7 +3,8 @@ const cosmosjs = require("../src"); // [WARNING] This mnemonic is just for the demo purpose. DO NOT USE THIS MNEMONIC for your own wallet. 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"; const chainId = "band-wenchang-mainnet"; -const band = cosmosjs.network("https://lcd-band.cosmostation.io", chainId); +// Please install and use rest server separately. (https://hub.cosmos.network/master/resources/service-providers.html#setting-up-the-rest-server) +const band = cosmosjs.network("YOUR REST SERVER URL", chainId); band.setBech32MainPrefix("band"); band.setPath("m/44'/494'/0'/0/0"); // new: m/44'/494'/0'/0/0, legacy: m/44'/118'/0'/0/0 const address = band.getAddress(mnemonic); diff --git a/example/browser-example.html b/example/browser-example.html index 7b4189e..3a85616 100644 --- a/example/browser-example.html +++ b/example/browser-example.html @@ -10,6 +10,8 @@ function send() { 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"; const chainId = "cosmoshub-3"; + // This rest server URL may be disabled at any time. In order to maintain stable blockchain service, it is recommended to prepare your rest server. + // (https://hub.cosmos.network/master/resources/service-providers.html#setting-up-the-rest-server) const cosmos = cosmosjs.network("https://lcd-cosmos-free.cosmostation.io", chainId); cosmos.setBech32MainPrefix("cosmos"); cosmos.setPath("m/44'/118'/0'/0/0"); diff --git a/example/cosmoshub.js b/example/cosmoshub.js index 3646d2f..8a80e88 100644 --- a/example/cosmoshub.js +++ b/example/cosmoshub.js @@ -3,6 +3,8 @@ const cosmosjs = require("../src"); // [WARNING] This mnemonic is just for the demo purpose. DO NOT USE THIS MNEMONIC for your own wallet. 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"; const chainId = "cosmoshub-3"; +// This rest server URL may be disabled at any time. In order to maintain stable blockchain service, it is recommended to prepare your rest server. +// (https://hub.cosmos.network/master/resources/service-providers.html#setting-up-the-rest-server) const cosmos = cosmosjs.network("https://lcd-cosmos-free.cosmostation.io", chainId); cosmos.setBech32MainPrefix("cosmos"); cosmos.setPath("m/44'/118'/0'/0/0"); diff --git a/example/iov.js b/example/iov.js index d3ed069..303b5a7 100644 --- a/example/iov.js +++ b/example/iov.js @@ -3,7 +3,8 @@ const cosmosjs = require("../src"); // [WARNING] This mnemonic is just for the demo purpose. DO NOT USE THIS MNEMONIC for your own wallet. 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"; const chainId = "iov-mainnet-2"; -const iov = cosmosjs.network("https://lcd-iov.cosmostation.io", chainId); +// Please install and use rest server separately. (https://hub.cosmos.network/master/resources/service-providers.html#setting-up-the-rest-server) +const iov = cosmosjs.network("YOUR REST SERVER URL", chainId); iov.setBech32MainPrefix("star"); iov.setPath("m/44'/234'/0'/0/0"); const address = iov.getAddress(mnemonic); diff --git a/example/irishub.js b/example/irishub.js index 196a144..b648f3a 100644 --- a/example/irishub.js +++ b/example/irishub.js @@ -3,7 +3,8 @@ const cosmosjs = require("../src"); // [WARNING] This mnemonic is just for the demo purpose. DO NOT USE THIS MNEMONIC for your own wallet. 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"; const chainId = "irishub"; -const iris = cosmosjs.network("https://lcd-iris.cosmostation.io", chainId); +// Please install and use rest server separately. (https://hub.cosmos.network/master/resources/service-providers.html#setting-up-the-rest-server) +const iris = cosmosjs.network("YOUR REST SERVER URL", chainId); iris.setBech32MainPrefix("iaa"); iris.setPath("m/44'/118'/0'/0/0"); const address = iris.getAddress(mnemonic); diff --git a/example/kava.js b/example/kava.js index 12133af..5dc1d8e 100644 --- a/example/kava.js +++ b/example/kava.js @@ -3,7 +3,8 @@ const cosmosjs = require("../src"); // [WARNING] This mnemonic is just for the demo purpose. DO NOT USE THIS MNEMONIC for your own wallet. 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"; const chainId = "kava-3"; -const kava = cosmosjs.network("https://lcd-kava-3.cosmostation.io", chainId); +// Please install and use rest server separately. (https://hub.cosmos.network/master/resources/service-providers.html#setting-up-the-rest-server) +const kava = cosmosjs.network("YOUR REST SERVER URL", chainId); kava.setBech32MainPrefix("kava"); kava.setPath("m/44'/459'/0'/0/0"); // new: m/44'/459'/0'/0/0, legacy: m/44'/118'/0'/0/0 const address = kava.getAddress(mnemonic); diff --git a/example/scrt.js b/example/scrt.js new file mode 100644 index 0000000..b0e4e3b --- /dev/null +++ b/example/scrt.js @@ -0,0 +1,40 @@ +const cosmosjs = require("../src"); + +// [WARNING] This mnemonic is just for the demo purpose. DO NOT USE THIS MNEMONIC for your own wallet. +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"; +const chainId = "secret-1"; +// Please install and use rest server separately. (https://hub.cosmos.network/master/resources/service-providers.html#setting-up-the-rest-server) +const scrt = cosmosjs.network("https://api-node.chainofsecrets.org", chainId); +scrt.setBech32MainPrefix("secret"); +scrt.setPath("m/44'/118'/0'/0/0"); +const address = scrt.getAddress(mnemonic); +const ecpairPriv = scrt.getECPairPriv(mnemonic); + +// Generate MsgSend transaction and broadcast +scrt.getAccounts(address).then(data => { + let stdSignMsg = scrt.newStdMsg({ + msgs: [ + { + type: "cosmos-sdk/MsgSend", + value: { + amount: [ + { + amount: String(100000), // 6 decimal places (1000000 uscrt = 1 SCRT) + denom: "uscrt" + } + ], + from_address: address, + to_address: "secret1quxn7c79z5vd85wzzpt4cxh0xcqyrl7fphcgx3" + } + } + ], + chain_id: chainId, + fee: { amount: [ { amount: String(5000), denom: "uscrt" } ], gas: String(200000) }, + memo: "", + account_number: String(data.result.value.account_number), + sequence: String(data.result.value.sequence) + }); + + const signedTx = scrt.sign(stdSignMsg, ecpairPriv); + scrt.broadcast(signedTx).then(response => console.log(response)); +}) \ No newline at end of file diff --git a/package.json b/package.json index d7f0e02..05d842f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@cosmostation/cosmosjs", - "version": "0.6.8", - "description": "A JavasSript Open Source Library for Cosmos Network, IRISnet, Kava, Band Protocol, and IOV. (HTML developers can use /dist/cosmos.js)", + "version": "0.6.9", + "description": "A JavasSript Open Source Library for Cosmos Network, IRISnet, Kava, Band Protocol, Starname and Secret Network. (HTML developers can use /dist/cosmos.js)", "main": "./src/index.js", "repository": { "type": "git", @@ -20,7 +20,10 @@ "iris", "kava", "band", - "iov" + "iov", + "starname", + "secret", + "scrt" ], "scripts": { "test": "mocha"