{"id":13746438,"url":"https://github.com/near/near-api-js","last_synced_at":"2026-01-25T18:15:46.092Z","repository":{"id":37082892,"uuid":"184860689","full_name":"near/near-api-js","owner":"near","description":"JavaScript library to interact with NEAR Protocol via RPC API","archived":false,"fork":false,"pushed_at":"2025-08-06T14:24:23.000Z","size":25485,"stargazers_count":411,"open_issues_count":66,"forks_count":255,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-08-09T22:35:09.029Z","etag":null,"topics":["blockchain","hacktoberfest","javascript","smartcontracts"],"latest_commit_sha":null,"homepage":"https://near.github.io/near-api-js","language":"TypeScript","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/near.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-05-04T06:33:50.000Z","updated_at":"2025-08-07T03:01:46.000Z","dependencies_parsed_at":"2023-12-21T20:32:02.635Z","dependency_job_id":"d9094854-72dd-46a3-bfd8-c0e02fa37c1d","html_url":"https://github.com/near/near-api-js","commit_stats":{"total_commits":1549,"total_committers":84,"mean_commits":18.44047619047619,"dds":0.6746287927695287,"last_synced_commit":"a025813e801e5e6c91c2ed953cead1f1c1cba407"},"previous_names":["nearprotocol/nearlib"],"tags_count":466,"template":false,"template_full_name":null,"purl":"pkg:github/near/near-api-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-api-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-api-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-api-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-api-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/near","download_url":"https://codeload.github.com/near/near-api-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/near%2Fnear-api-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269663711,"owners_count":24455836,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","hacktoberfest","javascript","smartcontracts"],"created_at":"2024-08-03T06:00:53.611Z","updated_at":"2026-01-25T18:15:46.062Z","avatar_url":"https://github.com/near.png","language":"TypeScript","funding_links":[],"categories":["Smart Contract Platforms","Libraries / Frameworks"],"sub_categories":[],"readme":"# NEAR JavaScript API\n\nNEAR JavaScript API is a complete library to interact with the NEAR blockchain. You can use it in the browser, or in Node.js runtime.\n\n\u003e [!IMPORTANT]  \n\u003e `near-api-js` is ideal to build backend services, CLIs, and scripts that interact with NEAR. For frontend development please check the official [web login docs](https://docs.near.org/web3-apps/concepts/web-login)\n\n## Why near-api-js?\n\n**near-api-js v7** is a single package that helps you to easily integrate NEAR blockchain into your JavaScript/TypeScript applications.\n\nIt includes all the functionality you need, including account management, transaction building, key management, interacting with smart contracts, making RPC calls, and more.\n\n- ✅ Simple - just one package\n- ✅ Batteries included - everything you need to build scripts and backend services\n- ✅ Friendly - multiple helpers to make your life easier\n- ✅ Full TypeScript support\n- ✅ Works in browser and Node.js\n\n## Quick Start\n\nAdd `near-api-js` to your project using your favorite package manager:\n\n```bash\nnpm install near-api-js\n# or\nyarn add near-api-js\n# or\npnpm add near-api-js\n```\n\nStart using it!\n\n```ts\nimport { Account, JsonRpcProvider, teraToGas, KeyPairString, nearToYocto } from \"near-api-js\";\n\n// Create a testnet provider\nconst provider = new JsonRpcProvider({\n  url: \"https://test.rpc.fastnear.com\",\n});\n\n// For read only calls, you can use the provider directly\nconst messages = await provider.callFunction({\n  contractId: 'guestbook.near-examples.testnet',\n  method: \"get_messages\",\n  args: {},\n});\n\nconsole.log(messages);\n\n// To modify state, you need an account to sign the transaction\nconst accountId: string = 'example.testnet';\nconst privateKey = 'ed25519:5nM...' as KeyPairString;\nconst account = new Account(accountId, provider, privateKey);\n\n// Call the contract\nawait account.callFunction({\n  contractId: 'guestbook.near-examples.testnet',\n  methodName: \"add_message\",\n  args: { text: \"Hello!\" },\n  gas: teraToGas('30'),\n  deposit: nearToYocto('0.1'),\n});\n```\n\n## Documentation\n\n- [Learn how to use](https://docs.near.org/tools/near-api) the library in your project\n- See it in action in our [API Examples](https://github.com/near-examples/near-api-examples/tree/main/near-api-js)\n- Read the [TypeDoc API](https://near.github.io/near-api-js/) documentation\n\n## Migration from @near-js/* packages\n\nCheck out the [migration guide](MIGRATION.md) to help you move from the old `@near-js/*` packages to `near-api-js`.\n\n## Features\n\n`near-api-js` includes some advanced features to help you build robust applications.\n\n### Simple Units Conversions\n\nYou can easily convert between NEAR and yoctoNEAR, and between gas units:\n\n```typescript\nimport { nearToYocto, yoctoToNear, teraToGas, gigaToGas } from 'near-api-js';\n\nawait account.callFunction({\n  contractId: 'example.testnet',\n  methodName: 'some_method',\n  args: {},\n  gas: teraToGas('30'),         // 30 TeraGas\n  deposit: nearToYocto('0.1'),  // 0.1 NEAR\n});\n\n// balance in NEAR with 2 decimals\nconst balance = yoctoToNear(await account.getBalance(), 2);\n\n```\n\n### Parallel Transactions\n`near-api-js` can send transactions in parallel by rotating multiple keys for an account.\n\n`nonce` collisions are automatically handled by retrying with incremented nonce.\n\n```typescript\nimport { Account, actions, JsonRpcProvider, KeyPair, MultiKeySigner } from \"near-api-js\"\nimport { NEAR } from \"near-api-js/tokens\"\n\nconst privateKey = ... // \nconst accountId = ... // \n\n// Create a connection to testnet RPC\nconst provider = new JsonRpcProvider({\n  url: \"https://test.rpc.fastnear.com\",\n})\n\n// Create an account object\nconst account = new Account(accountId, provider, privateKey)\n\n// create 10 keys and add them to the account\nconst keys = []\nconst txActions = []\nfor (let j = 0; j \u003c 10; j++) {\n  const newKeyPair = KeyPair.fromRandom('ed25519')\n  keys.push(newKeyPair)\n  txActions.push(\n    actions.addFullAccessKey(newKeyPair.getPublicKey())\n  )\n}\n\nawait account.signAndSendTransaction({\n  receiverId: accountId,\n  actions: txActions\n})\n\nconsole.log(`Added ${keys.length} keys to account ${accountId}`)\n\n// ------- Send NEAR tokens using multiple keys -------\nconst multiKeySigner = new MultiKeySigner(keys)\nconst multiAccount = new Account(accountId, provider, multiKeySigner)\n\nconst transfers = []\n\nfor (let i = 0; i \u003c 100; i++) {\n  transfers.push(\n    multiAccount.transfer(\n      {\n        token: NEAR,\n        amount: NEAR.toUnits(\"0.001\"),\n        receiverId: \"influencer.testnet\"\n      }\n    ))\n}\n\nconst sendNearTokensResults = await Promise.all(transfers)\nsendNearTokensResults.forEach(result =\u003e console.log(result))\n```\n\n### Typescript Support\n\n`near-api-js` is written in `TypeScript` and includes full type definitions:\n\n```typescript\nimport type {\n  AccountView,\n  BlockReference,\n  Action,\n  SignedTransaction\n} from 'near-api-js';\n```\n\n### Typed Function Calls\n\nYou can even type the expected results from contract function calls:\n\n```typescript\nconst provider = new JsonRpcProvider({\n  url: \"https://test.rpc.fastnear.com\",\n});\nconst account = new Account(\"accountId\", provider, \"privateKey\");\n\nawait provider.callFunction\u003cT\u003e()\nawait account.callFunction\u003cT\u003e()\n```\n\n### Failover RPC Provider\n\nYou can easily define multiple RPC endpoints to connect to  NEAR network, if one fails the next one will be used automatically.\n\n```typescript\nimport { JsonRpcProvider, FailoverRpcProvider } from 'near-api-js';\n\nconst provider = new FailoverRpcProvider([\n  new JsonRpcProvider({ url: 'https://rpc.mainnet.near.org' }),\n  new JsonRpcProvider({ url: 'https://rpc.mainnet.pagoda.co' }),\n]);\n```\n\n### Decoupled Transaction Signing\nYou can separately build transactions, sign them, and broadcast them to the network.\n\nThis is useful in scenarios where signing and sending need to be decoupled, such as offline signing\n\n```typescript\nimport { JsonRpcProvider, Account, KeyPairSigner, actions, nearToYocto, KeyPairString } from \"near-api-js\";\n\nconst provider = new JsonRpcProvider({\n  url: \"https://test.rpc.fastnear.com\",\n});\n\n// You can create a transaction only knowing the accountId and public key\nconst publicKey = '';\nconst accountId = '';\nconst account = new Account(accountId, provider);\n\nconst transaction = await account.createTransaction({\n  receiverId: \"receiver-account.testnet\",\n  actions: [actions.transfer(nearToYocto(\"0.1\"))],\n  publicKey: publicKey\n});\n\n// Whoever holds the private key can sign the transaction\nconst signer = KeyPairSigner.fromSecretKey(privateKey as KeyPairString);\nconst signResult = await signer.signTransaction(transaction);\nconsole.log(signResult.signedTransaction);\n\n// Anybody can send the signed transaction to the network\nconst sendTransactionResult = await provider.sendTransaction(signResult.signedTransaction);\nconsole.log(sendTransactionResult);\n```\n\n## Browser and Node.js Support\n\n- ✅ **Node.js** - Full support for Node.js 18+\n- ✅ **Browsers** - Works in all modern browsers\n- ✅ **ESM** - Native ES modules support\n- ✅ **CommonJS** - For legacy Node.js projects\n- ✅ **TypeScript** - Full type definitions included\n\n## Contributing\n\nContributions are welcome! Please check out the [contributing guidelines](https://github.com/near/near-api-js/blob/master/CONTRIBUTING.md).\n\n1. Install dependencies\n\n       pnpm install\n\n2. Run continuous build with:\n\n       pnpm -r compile -w\n\n### Integration Test\n\nSimply run:\n\n    pnpm test\n\n## License\n\nThis repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0).\nSee [LICENSE](https://github.com/near/near-api-js/blob/master/LICENSE) and [LICENSE-APACHE](https://github.com/near/near-api-js/blob/master/LICENSE-APACHE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnear%2Fnear-api-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnear%2Fnear-api-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnear%2Fnear-api-js/lists"}