{"id":19319675,"url":"https://github.com/blockcoders/near-rpc-providers","last_synced_at":"2025-04-22T17:31:57.654Z","repository":{"id":43724212,"uuid":"421370431","full_name":"blockcoders/near-rpc-providers","owner":"blockcoders","description":"Near JSON RPC Provider compatible with ethers.js","archived":false,"fork":false,"pushed_at":"2022-02-21T16:39:06.000Z","size":976,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-02T02:22:29.767Z","etag":null,"topics":["blockchain","ethers","ethersjs","json-rpc","near","near-rpc","rpc"],"latest_commit_sha":null,"homepage":"","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/blockcoders.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}},"created_at":"2021-10-26T09:57:56.000Z","updated_at":"2022-10-22T12:42:41.000Z","dependencies_parsed_at":"2022-09-01T11:32:01.135Z","dependency_job_id":null,"html_url":"https://github.com/blockcoders/near-rpc-providers","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockcoders%2Fnear-rpc-providers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockcoders%2Fnear-rpc-providers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockcoders%2Fnear-rpc-providers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blockcoders%2Fnear-rpc-providers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blockcoders","download_url":"https://codeload.github.com/blockcoders/near-rpc-providers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249595981,"owners_count":21297273,"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","ethers","ethersjs","json-rpc","near","near-rpc","rpc"],"created_at":"2024-11-10T01:24:47.631Z","updated_at":"2025-04-22T17:31:57.225Z","avatar_url":"https://github.com/blockcoders.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Near RPC Providers\n\n[![npm](https://img.shields.io/npm/v/near-rpc-providers)](https://www.npmjs.com/package/near-rpc-providers)\n[![CircleCI](https://circleci.com/gh/blockcoders/near-rpc-providers/tree/main.svg?style=svg)](https://circleci.com/gh/blockcoders/near-rpc-providers/tree/main)\n[![Coverage Status](https://coveralls.io/repos/github/blockcoders/near-rpc-providers/badge.svg?branch=main)](https://coveralls.io/github/blockcoders/near-rpc-providers?branch=main)\n[![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/near-rpc-providers)](https://snyk.io/test/github/blockcoders/near-rpc-providers)\n\nNear JSON RPC Provider compatible with [ethers.js](https://github.com/ethers-io/ethers.js/)\n\n## Install\n\n```sh\nnpm i near-rpc-providers\n```\n\n## Usage\n\n### Node\n\n```typescript\n// JavaScript\nconst { NearRpcProvider } = require('near-rpc-providers')\n\n// TypeScript\nimport { NearRpcProvider } from 'near-rpc-providers'\n```\n\n### Browser\n\nInclude the ESM module (near-rpc-providers.esm.js) and import using:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { NearRpcProvider } from './near-rpc-providers.esm.js'\n\u003c/script\u003e\n```\n\n## API\n\nThe `NearRpcProvider` is an extension over a regular [JsonRpcProvider](https://docs.ethers.io/v5/api/providers/jsonrpc-provider/#JsonRpcProvider) which is a popular method for interacting with the blockchain.\n\n### Initializing\n\n```typescript\n// Use a network name of chainId to initialize, see src/networks.ts\nconst nearRpcProvider = new NearRpcProvider('near')\n```\n\n## Methods\n\n### Block Number\n\nReturns the block number of the latest block\n\n```typescript\nconst blockNumber = await nearRpcProvider.getBlockNumber()\n```\n\n### Call a Contract Function\n\nAllows you to call a contract method as a view function.\n\n```typescript\nconst contractResponse = await nearRpcProvider.contractCall(\n  'example.testnet', 'latest', 'getMessages', 'e30='\n)\n```\n\n### Get an Account Balance\n\nReturns a BigNumber representing the balance on the provided account\n\n```typescript\nconst balance = await nearRpcProvider.getBalance('example.testnet')\n```\n\n### Get an Access Key\n\nReturns information about a single access key for given account.\n\n```typescript\nconst accessKey = await nearRpcProvider.getAccessKey(\n  'example.testnet',\n  'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',\n  75866664,\n)\n```\n\n### Get an Access Key List\n\nReturns all access keys for a given account. You can querying it by `finality`:\n\n```typescript\nconst accessKeyList = await nearRpcProvider.getAccessKeyList('example.testnet', 'latest')\n```\n\nBy `block_height`:\n\n```typescript\nconst accessKeyList = await nearRpcProvider.getAccessKeyList('example.testnet', 27912554)\n```\n\nOr by `block_hash`:\n\n```typescript\nconst accessKeyList = await nearRpcProvider.getAccessKeyList(\n  'example.testnet', '3Xz2wM9rigMXzA2c5vgCP8wTgFBaePucgUmVYPkMqhRL'\n)\n```\n\n### Get Block\n\nUse Get Block With Chunk instead of this method.\n\n### Get Block With Chunk\n\nReturns block for given `finality`:\n\n```typescript\nconst block = await nearRpcProvider.getBlockWithChunk({\n  finality: 'final' })\n```\n\nOr `block_id`:\n\n```typescript\nconst block = await nearRpcProvider.getBlockWithChunk({ \n  block_id: '81k9ked5s34zh13EjJt26mxw5npa485SY4UNoPi6yYLo',\n})\n```\n\n### Get Chunk Details\n\nReturns details of a specific chunk. You can get the chunk details by `chunk_id`:\n\n```typescript\nconst chunk = await nearRpcProvider.getChunkDetails({\n  chunk_id: 'EBM2qg5cGr47EjMPtH88uvmXHDHqmWPzKaQadbWhdw22',\n})\n```\n\nOr by `block_id` and `shard_id`:\n\n```typescript\nconst chunk = await nearRpcProvider.getChunkDetails({\n  block_id: 58934027, \n  shard_id: 0,\n})\n```\n\n### Get Contract Code\n\nReturn the code encoded in base64. You can get the contract code by `block_hash`:\n\n```typescript\nconst code = await nearRpcProvider.getCode(\n  'example.testnet', '4fzLVR8cfyRDi5hDstYQy73eoxMJdWsH72KM6N9TmYmq'\n)\n```\n\nOr by `block_tag`:\n\n```typescript\nconst code = await nearRpcProvider.getCode('example.testnet', 'latest')\n```\n\n### Get Contract State\n\nReturns the state of a contract based on the key prefix (base64 encoded). You can get it by `block_tag`:\n\n```typescript\nconst state = await nearRpcProvider.getContractState('example.testnet', 'latest')\n```\n\nBy `block_height`:\n\n```typescript\nconst state = await nearRpcProvider.getContractState('example.testnet', 58934027)\n```\n\nOr `block_hash`: \n\n```typescript\nconst state = await nearRpcProvider.getContractState(\n  'example.testnet', '3Xz2wM9rigMXzA2c5vgCP8wTgFBaePucgUmVYPkMqhRL'\n)\n```\n\n### Get Default Provider\n\nReturns the default provider.\n\n```typescript\nconst defaultProvider = getDefaultProvider({\n  name: 'neartestnet',\n  chainId: parseInt(Buffer.from('testnet').toString('hex'), 16),\n})\n```\n\n### Get Gas Price\n\nReturns a BigNumber representing the current `gasPrice`\n\n```typescript\nconst gasPrice = await nearRpcProvider.getGasPrice()\n```\n\n### Get Network Info\n\nReturns the current state of node network connections.\n\n```typescript\nconst network = await nearRpcProvider.getNetworkInfo()\n```\n\n### Get Validator Status\n\nReturns details and the state of validation on the blockchain. It must be used with an array of `block_hash`:\n\n```typescript\nconst validator = await nearRpcProvider.getValidatorStatus(\n  ['FiG2nMjjue3YdgYAyM3ZqWXSaG6RJj5Gk7hvY8vrEoGw']\n)\n```\n\n`block_height`:\n\n```typescript\nconst validator = await nearRpcProvider.getValidatorStatus([17791098])\n```\n\nOr `null`:\n\n```typescript\nconst validator = await nearRpcProvider.getValidatorStatus([null])\n```\n\n### Send Transaction\n\nSends a transaction to be executed asynchronously. Returns a transaction that can be waited for using `transaction.wait()`\n\n```typescript\nconst transaction = await nearRpcProvider.sendTransaction(\n  'DgAAAHNlbmRlci50ZXN0bmV0AOrmAai64SZOv9e/naX4W15pJx0GAap35wTT1T/DwcbbDwAAAAAAAAAQAAAAcmVjZWl2ZXIudGVzdG5ldNMnL7URB1cxPOu3G8jTqlEwlcasagIbKlAJlF5ywVFLAQAAAAMAAACh7czOG8LTAAAAAAAAAGQcOG03xVSFQFjoagOb4NBBqWhERnnz45LY4+52JgZhm1iQKz7qAdPByrGFDQhQ2Mfga8RlbysuQ8D8LlA6bQE=',\n)\n\nconst receipt = await tx.wait()\n```\n\n### Send\n\nAllows sending a request directly to the NEAR RPC, using the given `method` and `params`.\n\nSee https://docs.near.org/docs/api/rpc for all available options\n\n```typescript\nconst blockResponse = await this.send\u003cBlockRpcResponse\u003e('block', { block_id: params.block_id })\n```\n\n### Sign a transaction\n\nReturn a transaction signed.\n\n```typescript\nconst [hash, signedTransaction] = await getSignedTransaction(nearRpcProvider)\n```\n\nAfter to get the signed transaction, you'll be able to execute that signed transaction:\n\n```typescript\nconst txString = Buffer.from(signedTransaction.encode()).toString('base64')\nconst response = await nearRpcProvider.sendTransaction(txString)\n```\n\n## Running a NEAR network locally\n\nFollow the documentation [here](https://github.com/kurtosis-tech/near-kurtosis-module#near-kurtosis-module) to set up a NEAR network locally on your machine using [Kurtosis](https://docs.kurtosistech.com/).\n\n## Change Log\n\nSee [Changelog](CHANGELOG.md) for more information.\n\n## Contributing\n\nContributions welcome! See [Contributing](CONTRIBUTING.md).\n\n## Collaborators\n\n- [**Jose Ramirez**](https://github.com/jarcodallo), [Twitter](https://twitter.com/jarcodallo), [NPM](https://www.npmjs.com/~jarcodallo)\n- [**Brian Zuker**](https://github.com/bzuker)\n- [**Ana Riera**](https://github.com/AnnRiera)\n\n## Acknowledgements\n\nThis project was kindly sponsored by [Near](https://near.org/).\n\n## License\n\nLicensed under the MIT - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockcoders%2Fnear-rpc-providers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblockcoders%2Fnear-rpc-providers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblockcoders%2Fnear-rpc-providers/lists"}