{"id":13565544,"url":"https://github.com/cosmostation/cosmosjs","last_synced_at":"2025-04-03T22:31:41.404Z","repository":{"id":36370397,"uuid":"187190516","full_name":"cosmostation/cosmosjs","owner":"cosmostation","description":":star: CosmosJS - Cosmos JavaScript Library","archived":true,"fork":false,"pushed_at":"2022-04-15T06:00:10.000Z","size":1821,"stargazers_count":165,"open_issues_count":1,"forks_count":78,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-04T19:41:50.077Z","etag":null,"topics":["akash-network","amino","atom","band","blockchain","certik","cosmos","cosmos-address","cosmos-sdk","cosmosjs","iov","iris","juno","kava","protobuf","secret-network","sign","tendermint","wasm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cosmostation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-17T09:45:20.000Z","updated_at":"2024-09-22T13:11:10.000Z","dependencies_parsed_at":"2022-08-08T14:17:11.004Z","dependency_job_id":null,"html_url":"https://github.com/cosmostation/cosmosjs","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosmostation%2Fcosmosjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosmostation%2Fcosmosjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosmostation%2Fcosmosjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosmostation%2Fcosmosjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cosmostation","download_url":"https://codeload.github.com/cosmostation/cosmosjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247090271,"owners_count":20881941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["akash-network","amino","atom","band","blockchain","certik","cosmos","cosmos-address","cosmos-sdk","cosmosjs","iov","iris","juno","kava","protobuf","secret-network","sign","tendermint","wasm"],"created_at":"2024-08-01T13:01:49.730Z","updated_at":"2025-04-03T22:31:40.263Z","avatar_url":"https://github.com/cosmostation.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003c!-- TOTAL-DOWNLOADS-BADGE:START - Do not remove or modify this section --\u003e\n[![NPM Downloads](https://img.shields.io/npm/dt/@cosmostation/cosmosjs.svg)](https://www.npmjs.com/package/@cosmostation/cosmosjs)\n\u003c!-- TOTAL-DOWNLOADS-BADGE:END --\u003e\n\n\u003e **IMPORTANT** THIS REPO IS DEPRECATED. Please use [cosmos/cosmjs](https://github.com/cosmos/cosmjs) instead of this repository.\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.cosmostation.io\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg width=\"500\" src=\"https://user-images.githubusercontent.com/34641838/151108162-216c3b7e-aa43-47be-8298-b7f20e669af9.png\" alt=\"Cosmostation logo\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003ch1 align=\"center\"\u003e\n    CosmosJS - Cosmos JavaScript Library \n\u003c/h1\u003e\n\n*:star: Developed / Developing by [Cosmostation](https://www.cosmostation.io/)*\n\nA Javascript Open Source Library for blockchain made using by Cosmos SDK like [Cosmoshub](https://cosmos.network/), [IRISnet](https://www.irisnet.org/), [Akash Network](https://akash.network/), and [Juno](https://www.junonetwork.io/).\n\nThis library supports cosmos address generation and verification. It enables you to create an offline signature functions of different types of transaction messages. It will eventually support all the other blockchains that are based on Tendermint in the future.\n\n\u003e :warning: If you need for classic version for amino signing, download a version under v0.9.7\n\n[![License](https://img.shields.io/npm/l/@cosmostation/cosmosjs.svg)](https://www.npmjs.com/package/@cosmostation/cosmosjs)\n[![Latest Stable Version](https://img.shields.io/npm/v/@cosmostation/cosmosjs.svg)](https://www.npmjs.com/package/@cosmostation/cosmosjs)\n[![NPM Downloads](https://img.shields.io/npm/dm/@cosmostation/cosmosjs.svg)](https://www.npmjs.com/package/@cosmostation/cosmosjs)\n\n## Installation\n\nIn order to fully use this library, you need to run a local or remote full node and set up its rest server, which acts as an intermediary between the front-end and the full-node.\n\n### NPM (Protobuf)\n\n```bash\nnpm install @cosmostation/cosmosjs\n```\n\n### Yarn (Protobuf)\n\n```bash\nyarn add @cosmostation/cosmosjs\n```\n\n### NPM (Amino)\n- https://github.com/cosmostation/cosmosjs/tree/classic\n\n```bash\nnpm install @cosmostation/cosmosjs@0.9.7\n```\n\n### Yarn (Amino)\n- https://github.com/cosmostation/cosmosjs/tree/classic\n\n```bash\nyarn add @cosmostation/cosmosjs@0.9.7\n```\n\n## Import \n\n```js\nimport { Cosmos } from \"../src/index.js\";\n```\n\n## Usage\n\n- You need to import Cosmos-sdk Protobuf message file as js. It is created by [gen-proto.sh](https://github.com/cosmos-client/cosmos-client-ts/blob/master/gen-proto.sh).\n- @cosmostation/cosmosjs@0.10.0+ is running above nodejs v14+\n- You can run with this option for ES6.\n```sh\n$ node --es-module-specifier-resolution=node example/cosmoshub.js\n```\n\n- Import the message file that is converted from Cosmos-sdk proto.\n\n```js\nimport message from \"@cosmostation/cosmosjs/src/messages/proto\";\n```\n\n- Stargate-final: Generate Cosmos address from mnemonic \n```js\nconst mnemonic = \"...\"\nconst chainId = \"cosmoshub-4\";\nconst cosmos = new Cosmos(lcdUrl, chainId);\n\ncosmos.setPath(\"m/44'/118'/0'/0/0\");\nconst address = cosmos.getAddress(mnemonic);\n\n```\n\nGenerate both privKey and pubKeyAny that are needed for signing. \n```js\nconst privKey = cosmos.getECPairPriv(mnemonic);\nconst pubKeyAny = cosmos.getPubKeyAny(privKey);\n```\n\nTransfer ATOM to designated address. \n* Make sure to input proper type, account number, and sequence of the cosmos account to generate protobuf structure. You can get those account information on blockchain. Protobuf signing is different from Amino signing.\n```js\ncosmos.getAccounts(address).then(data =\u003e {\n\t// signDoc = (1)txBody + (2)authInfo\n\t// ---------------------------------- (1)txBody ----------------------------------\n\tconst msgSend = new message.cosmos.bank.v1beta1.MsgSend({\n\t\tfrom_address: address,\n\t\tto_address: \"cosmos1jf874x5vr6wkza6ahvamck4sy4w76aq4w9c4s5\",\n\t\tamount: [{ denom: \"uatom\", amount: String(100000) }]\t\t// 6 decimal places (1000000 uatom = 1 ATOM)\n\t});\n\n\tconst msgSendAny = new message.google.protobuf.Any({\n\t\ttype_url: \"/cosmos.bank.v1beta1.MsgSend\",\n\t\tvalue: message.cosmos.bank.v1beta1.MsgSend.encode(msgSend).finish()\n\t});\n\n\tconst txBody = new message.cosmos.tx.v1beta1.TxBody({ messages: [msgSendAny], memo: \"\" });\n\n\t// --------------------------------- (2)authInfo ---------------------------------\n\tconst signerInfo = new message.cosmos.tx.v1beta1.SignerInfo({\n\t\tpublic_key: pubKeyAny,\n\t\tmode_info: { single: { mode: message.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT } },\n\t\tsequence: data.account.sequence\n\t});\n\n\tconst feeValue = new message.cosmos.tx.v1beta1.Fee({\n\t\tamount: [{ denom: \"uatom\", amount: String(5000) }],\n\t\tgas_limit: 200000\n\t});\n\n\tconst authInfo = new message.cosmos.tx.v1beta1.AuthInfo({ signer_infos: [signerInfo], fee: feeValue });\n\n\t...\n});\n```\n\nSign transaction by using stdSignMsg and broadcast by using [/cosmos/tx/v1beta1/txs](https://v1.cosmos.network/rpc/v0.41.4) REST API\n```js\nconst signedTxBytes = cosmos.sign(txBody, authInfo, data.account.account_number, privKey);\ncosmos.broadcast(signedTxBytes).then(response =\u003e console.log(response));\n```\n\nNow it is time to transfer CW20 tokens via Cosmosjs! Copy the CW20 contract into the variable of cw20Contract. You can instantiate and execute cosmwasm contracts on JUNO. It is possible to create your own CW20 token [here](https://junomint.ezstaking.io/).\n```js\ncosmos.getAccounts(address).then(data =\u003e {\n\t// signDoc = (1)txBody + (2)authInfo\n\t// ---------------------------------- (1)txBody ----------------------------------\n\tlet cw20Contract = \"juno10rktvmllvgctcmhl5vv8kl3mdksukyqf2tdveh8drpn0sppugwwqjzz30z\";\n\tlet transferBytes = new Buffer('{\"transfer\":{\"amount\":\"1\",\"recipient\":\"juno1cx4nq77x3unvl2xsa9fmm9drxkexzkjnzwt2y7\"}}');\n\tconst msgExecuteContract = new message.cosmwasm.wasm.v1.MsgExecuteContract({\n\t\tsender: address,\n\t\tcontract: cw20Contract,\n\t\tmsg: transferBytes,\n\t\tfunds: []\n\t});\n\n\tconst msgExecuteContractAny = new message.google.protobuf.Any({\n\t\ttype_url: \"/cosmwasm.wasm.v1.MsgExecuteContract\",\n\t\tvalue: message.cosmwasm.wasm.v1.MsgExecuteContract.encode(msgExecuteContract).finish()\n\t});\n\n\tconst txBody = new message.cosmos.tx.v1beta1.TxBody({ messages: [msgExecuteContractAny], memo: \"\" });\n});\n```\n\nIn addition, you can query CW20 token balance using wasmQuery.\n```js\ncosmos.wasmQuery(\n\t'juno168ctmpyppk90d34p3jjy658zf5a5l3w8wk35wht6ccqj4mr0yv8s4j5awr',\n\t'{\"balance\": {\"address\": \"juno1sautwkp7mzftvqtct3ugtq9xuuq680tzqzvf5g\"}}'\n).then(json =\u003e {\n\tlet smartCode = json.result.smart;\n\tlet decoded = new Buffer(smartCode, 'base64').toString();\n\tlet parsed = JSON.parse(decoded);\n\n\tconsole.log(\"NETA balance: \", parsed.balance);\n})\n```\n\nOfficial LCD url([https://api.cosmos.network](https://api.cosmos.network/node_info)).\n- 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.\n- Setting up the rest server: (https://docs.cosmos.network/master/core/grpc_rest.html#rest-server)\n\n## Supporting Message Types (Updating...)\n\nWe will continue to update the protobuf signing structure.\n\n## Documentation\n\nThis library is simple and easy to use. We don't have any formal documentation yet other than examples. Ask for help if our examples aren't enough to guide you\n\n## Contribution\n\n- Contributions, suggestions, improvements, and feature requests are always welcome\n\nWhen opening a PR with a minor fix, make sure to add #trivial to the title/description of said PR.\n\n## Cosmostation's Services and Community\n\n- [Official Website](https://www.cosmostation.io)\n- [Mintscan Explorer](https://www.mintscan.io)\n- [Web Wallet](https://wallet.cosmostation.io)\n- [Android Wallet](https://bit.ly/2BWex9D)\n- [iOS Wallet](https://apple.co/2IAM3Xm)\n- [Telegram - International](https://t.me/cosmostation)\n- [Kakao - Koreans](https://open.kakao.com/o/g6KKSe5)\n\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://www.cosmostation.io/\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/34641838?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBooyoun\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=Booyoun-Kim\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/cosmostation/cosmosjs/issues?q=author%3ABooyoun-Kim\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#maintenance-Booyoun-Kim\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://jaybdev.net\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/20435620?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJayB\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=kogisin\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=kogisin\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#maintenance-kogisin\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://clovers.network\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/964052?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ebilly rennekamp\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=okwme\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/cosmostation/cosmosjs/issues?q=author%3Aokwme\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/tonyfeung\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/5483234?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTony Phuong Nguyen\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=tonyfeung\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/Tosch110\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/8368497?s=460\u0026u=f82d3c518432276c191dc00f1524b7d8098bf828\u0026v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTobias Schwarz\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=Tosch110\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/scottburch\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/103808?s=460\u0026v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003e\nScott Burch\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=scottburch\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/okwme\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/1866496?s=460\u0026v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ebilly rennekamp\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=okwme\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/pgrimaud\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/5483234?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ePierre Grimaud\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=pgrimaud\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/levackt\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/10286403?s=460\u0026v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTaariq Levack\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=levackt\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/atmoner\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1071490?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eɐʇɯon3ɹ\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/cosmostation/cosmosjs/commits?author=atmoner\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmostation%2Fcosmosjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosmostation%2Fcosmosjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmostation%2Fcosmosjs/lists"}