{"id":13792331,"url":"https://github.com/evmos/evmosjs","last_synced_at":"2025-05-12T14:31:50.371Z","repository":{"id":37961580,"uuid":"463145239","full_name":"evmos/evmosjs","owner":"evmos","description":"JS and TS libs for Evmos","archived":true,"fork":false,"pushed_at":"2023-10-13T10:03:23.000Z","size":3371,"stargazers_count":65,"open_issues_count":25,"forks_count":56,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-07T19:50:40.493Z","etag":null,"topics":["blockchain","cosmos","evmos","javascript","npm","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/evmosjs","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evmos.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-24T12:45:44.000Z","updated_at":"2024-11-30T05:52:04.000Z","dependencies_parsed_at":"2024-08-03T22:06:32.440Z","dependency_job_id":"90272cb4-ebe7-4569-a8f3-81c2575a749a","html_url":"https://github.com/evmos/evmosjs","commit_stats":null,"previous_names":[],"tags_count":111,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmos%2Fevmosjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmos%2Fevmosjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmos%2Fevmosjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmos%2Fevmosjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evmos","download_url":"https://codeload.github.com/evmos/evmosjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253754967,"owners_count":21958934,"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":["blockchain","cosmos","evmos","javascript","npm","typescript"],"created_at":"2024-08-03T22:01:11.073Z","updated_at":"2025-05-12T14:31:49.029Z","avatar_url":"https://github.com/evmos.png","language":"TypeScript","readme":"# evmosjs\n\n\u003e ⚠️ This librairy is no longer maintained. Many of the features are no longer working due to changes in the [Evmos protocol](https://github.com/evmos/evmos) that were not mirrored in this repository.\n\u003e \n\u003e Also we encourage builders to interact with the protocol using [EVM Extensions](https://docs.evmos.org/develop/smart-contracts/evm-extensions) instead of building complex Cosmos transactions. EVM Extensions are basically precompiled stateful smart contracts. You can interact with them the same way you interact with EVM Solidity smart contracts.\n\u003e \n\u003e For examples on how to integrate with Keplr, Metamask or how to process cosmos or evm transactions we invite you to checkout this repository as a reference: https://github.com/evmos/apps\n\n## Installation\n\nevmosjs uses [buf.build](https://buf.build/) to manage [Evmos Protobuf dependencies](https://buf.build/evmos). To install evmosjs packages in your project,\nfollow the instructions corresponding to your package manager.\n\n### NPM\n\nAdd the following line to an `.npmrc` file in your project root:\n\n```ini\n@buf:registry=https://buf.build/gen/npm/v1\n```\n\nThen run:\n\n```bash\nnpm install evmosjs\n```\n\nOr:\n\n```bash\nnpm install @evmos/\u003cpackage\u003e\n```\n\n### Yarn v2.x or v3.x\n\nAdd the following to an `.yarnrc.yml` file in your project root:\n\n```yaml\nnpmScopes:\n  buf:\n    npmRegistryServer: \"https://buf.build/gen/npm/v1\"\n```\n\nThen run:\n\n```bash\nyarn add evmosjs\n```\n\nOr:\n\n```bash\nyarn add @evmos/\u003cpackage\u003e\n```\n\nNote that Yarn v1 is not supported ([see explanation](https://docs.buf.build/bsr/remote-packages/npm#other-package-managers)).\n\n## Usage and Examples\n\n### Query an Account\n\nQuery the account number, sequence, and pubkey for a given address.\n\n```ts\nimport { generateEndpointAccount } from '@evmos/provider'\n\nconst address = 'evmos1...'\n\n// Find node urls for either mainnet or testnet here:\n// https://docs.evmos.org/develop/api/networks.\nconst nodeUrl = '...'\nconst queryEndpoint = `${nodeUrl}${generateEndpointAccount(address)}`\n\nconst restOptions = {\n  method: 'GET',\n  headers: { 'Content-Type': 'application/json' },\n}\n\n// Note that the node will return a 400 status code if the account does not exist.\nconst rawResult = await fetch(\n  queryEndpoint,\n  restOptions,\n)\n\nconst result = await rawResult.json()\n\n// The response format is available at @evmos/provider/rest/account/AccountResponse.\n// Note that the `pub_key` will be `null` if the address has not sent any transactions.\n/*\n  account: {\n    '@type': string\n    base_account: {\n      address: string\n      pub_key?: {\n        '@type': string\n        key: string\n      }\n      account_number: string\n      sequence: string\n    }\n    code_hash: string\n  }\n*/\n```\n\n### Get an Account's Public Key\n\nUse Keplr or MetaMask to retrieve an account's public key\nif it is not returned in the query response.\nThe public key is necessary in order to sign and broadcast\ntransactions, and it must be encoded as a compressed key in\n`base64`.\n\n#### Keplr\n\n```ts\nconst cosmosChainID = 'evmos_9001-2' // Use 'evmos_9000-4' for testnet\n\nconst account = await window?.keplr?.getKey(cosmosChainID)\nconst pk = Buffer.from(account.pubKey).toString('base64')\n```\n\n#### MetaMask\n\nSince MetaMask does not provide an interface to retrieve a user's\npublic key, we must sign a message and\n[recover the key from a signature](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm#Public_key_recovery).\n\n```ts\nimport { hashMessage } from '@ethersproject/hash'\nimport {\n  computePublicKey,\n  recoverPublicKey,\n} from '@ethersproject/signing-key'\n\nconst accounts = await window?.ethereum?.request({\n  method: 'eth_requestAccounts',\n})\n\n// Handle errors if MetaMask fails to return any accounts.\nconst message = 'Verify Public Key'\n\nconst signature = await window?.ethereum?.request({\n  method: 'personal_sign',\n  params: [message, accounts[0], ''],\n})\n\n// Compress the key, since the client expects\n// public keys to be compressed.\nconst uncompressedPk = recoverPublicKey(\n  hashMessage(message),\n  signature,\n)\n\nconst hexPk = computePublicKey(uncompressedPk, true)\nconst pk = Buffer.from(\n  hexPk.replace('0x', ''), 'hex',\n).toString('base64')\n```\n\n### Create a Signable Transaction\n\nCreate a transaction payload which can be signed using either Metamask or Keplr.\n\nThis example uses `MsgSend`. View all signable transaction payloads in the [Transaction Docs](https://github.com/evmos/evmosjs/tree/main/docs/transactions).\n\n```ts\nimport {\n  Chain,\n  Sender,\n  Fee,\n  TxContext,\n  MsgSendParams,\n  createTxMsgSend,\n  TxPayload,\n} from '@evmos/transactions'\n\nconst chain: Chain = {\n  chainId: 9001,\n  cosmosChainId: 'evmos_9001-2',\n}\n\n// Populate the transaction sender parameters using the\n// query API.\nconst sender: Sender = {\n  accountAddress: \u003csender_account_address\u003e,\n  sequence: \u003csender_sequence\u003e,\n  accountNumber: \u003csender_account_number\u003e,\n  // Use the public key from the account query, or retrieve\n  // the public key from the code snippet above.\n  pubkey: \u003csender_pub_key\u003e,\n}\n\nconst fee: Fee = {\n  amount: '4000000000000000',\n  denom: 'aevmos',\n  gas: '200000',\n}\n\nconst memo = ''\n\nconst context: TxContext = {\n  chain,\n  sender,\n  fee,\n  memo,\n}\n\nconst params: MsgSendParams = {\n  destinationAddress: \u003cdestination_address\u003e,\n  amount: \u003ctransaction_amount\u003e,\n  denom: 'aevmos',\n}\n\nconst tx: TxPayload = createTxMsgSend(context, params)\n```\n\n### Sign the Transaction with MetaMask\n\nEvmos supports EIP-712 signatures for Cosmos payloads to be signed using Ethereum wallets such as MetaMask.\n\n```ts\nimport { createTxRaw } from '@evmos/proto'\nimport { evmosToEth } from '@evmos/address-converter'\n\n// First, populate a TxContext object and create a signable Tx payload.\n// (See 'Create a Signable Transaction' to learn how to create these).\nconst context = ...\nconst tx = ...\n\nconst { sender } = context\n\n// Initialize MetaMask and sign the EIP-712 payload.\nawait window.ethereum.enable()\n\nconst senderHexAddress = evmosToEth(sender.accountAddress)\nconst eip712Payload = JSON.stringify(tx.eipToSign)\n\nconst signature = await window.ethereum.request({\n  method: 'eth_signTypedData_v4',\n  params: [senderHexAddress, eip712Payload],\n})\n\n// Create a signed Tx payload that can be broadcast to a node.\nconst signatureBytes = Buffer.from(signature.replace('0x', ''), 'hex')\n\nconst { signDirect } = tx\nconst bodyBytes = signDirect.body.toBinary()\nconst authInfoBytes = signDirect.authInfo.toBinary()\n\nconst signedTx = createTxRaw(\n  bodyBytes,\n  authInfoBytes,\n  [signatureBytes],\n)\n```\n\n### Sign the Transaction with Keplr (SignDirect)\n\nEvmosJS supports Cosmos SDK `SignDirect` payloads that can be signed using Keplr.\n\n```ts\nimport { createTxRaw } from '@evmos/proto'\n\n// First, populate a TxContext object and create a signable Tx payload.\n// (See 'Create a Signable Transaction' to learn how to create these).\nconst context = ...\nconst tx = ...\n\nconst { chain, sender } = context\nconst { signDirect } = tx\n\nconst signResponse = await window?.keplr?.signDirect(\n  chain.cosmosChainId,\n  sender.accountAddress,\n  {\n    bodyBytes: signDirect.body.toBinary(),\n    authInfoBytes: signDirect.authInfo.toBinary(),\n    chainId: chain.cosmosChainId,\n    accountNumber: new Long(sender.accountNumber),\n  },\n)\n\nif (!signResponse) {\n  // Handle signature failure here.\n}\n\nconst signatures = [\n  new Uint8Array(Buffer.from(signResponse.signature.signature, 'base64')),\n]\n\nconst { signed } = signResponse\n\nconst signedTx = createTxRaw(\n  signed.bodyBytes,\n  signed.authInfoBytes,\n  signatures,\n)\n```\n\n### Sign the Transaction with Keplr (EIP-712)\n\nEvmosJS also supports signing [EIP-712](https://eips.ethereum.org/EIPS/eip-712) payloads using Keplr. This is necessary for Ledger users on Keplr, since the Ledger device cannot sign `SignDirect` payloads.\n\n```ts\nimport { EthSignType } from '@keplr-wallet/types';\nimport { createTxRaw } from '@evmos/proto'\n\n// First, populate a TxContext object and create a signable Tx payload.\n// (See 'Create a Signable Transaction' to learn how to create these).\nconst context = ...\nconst tx = ...\n\nconst { chain, sender } = context\n\nconst eip712Payload = JSON.stringify(tx.eipToSign)\nconst signature = await window?.keplr?.signEthereum(\n  chain.cosmosChainId,\n  sender.accountAddress,\n  eip712Payload,\n  EthSignType.EIP712,\n)\n\nif (!signature) {\n  // Handle signature failure here.\n}\n\nconst { signDirect } = tx\nconst bodyBytes = signDirect.body.toBinary()\nconst authInfoBytes = signDirect.authInfo.toBinary()\n\nconst signedTx = createTxRaw(\n  bodyBytes,\n  authInfoBytes,\n  [signature],\n)\n```\n\n### Broadcast the Signed Transaction\n\nRegardless of how the transaction is signed, broadcasting takes place the same way.\n\n```ts\nimport {\n  generateEndpointBroadcast,\n  generatePostBodyBroadcast,\n} from '@evmos/provider'\n\n// First, sign a transaction using MetaMask or Keplr.\nconst signedTx = createTxRaw(...)\n\n// Find a node URL from a network endpoint:\n// https://docs.evmos.org/develop/api/networks.\nconst nodeUrl = ...\n\nconst postOptions = {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json' },\n  body: generatePostBodyBroadcast(signedTx),\n}\n\nconst broadcastEndpoint = `${nodeUrl}${generateEndpointBroadcast()}`\nconst broadcastPost = await fetch(\n  broadcastEndpoint,\n  postOptions,\n)\n\nconst response = await broadcastPost.json()\n```\n","funding_links":[],"categories":["Dev Tools"],"sub_categories":["Launchpads, Incubators, Accelerators and Ecosystem Supporters"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevmos%2Fevmosjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevmos%2Fevmosjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevmos%2Fevmosjs/lists"}