Skip to main content
Version: near-api-js@1.1.0

Class: JsonRpcProvider

providers/json-rpc-provider.JsonRpcProvider

Client class to interact with the NEAR RPC API.

See

https://github.com/near/nearcore/tree/master/chain/jsonrpc

Hierarchy​

  • Provider

    ↳ JsonRpcProvider

Constructors​

constructor​

new JsonRpcProvider(connectionInfo)

Parameters​

NameTypeDescription
connectionInfoConnectionInfoConnection info

Overrides​

Provider.constructor

Defined in​

providers/json-rpc-provider.ts:60

Methods​

accessKeyChanges​

accessKeyChanges(accountIdArray, blockQuery): Promise<ChangeResult>

Gets access key changes for a given array of accountIds See docs for more info

Parameters​

NameType
accountIdArraystring[]
blockQueryBlockReference

Returns​

Promise<ChangeResult>

Overrides​

Provider.accessKeyChanges

Defined in​

providers/json-rpc-provider.ts:222


accountChanges​

accountChanges(accountIdArray, blockQuery): Promise<ChangeResult>

Gets account changes for a given array of accountIds pass block_id OR finality as blockQuery, not both See docs for more info

Parameters​

NameType
accountIdArraystring[]
blockQueryBlockReference

Returns​

Promise<ChangeResult>

Overrides​

Provider.accountChanges

Defined in​

providers/json-rpc-provider.ts:256


block​

block(blockQuery): Promise<BlockResult>

Query for block info from the RPC pass block_id OR finality as blockQuery, not both

See

https://docs.near.org/api/rpc/block-chunk

Parameters​

NameTypeDescription
blockQueryBlockId | BlockReferenceBlockReference (passing a BlockId is deprecated)

Returns​

Promise<BlockResult>

Overrides​

Provider.block

Defined in​

providers/json-rpc-provider.ts:162


blockChanges​

blockChanges(blockQuery): Promise<BlockChangeResult>

Query changes in block from the RPC pass block_id OR finality as blockQuery, not both

See

https://docs.near.org/api/rpc/block-chunk

Parameters​

NameType
blockQueryBlockReference

Returns​

Promise<BlockChangeResult>

Overrides​

Provider.blockChanges

Defined in​

providers/json-rpc-provider.ts:173


chunk​

chunk(chunkId): Promise<ChunkResult>

Queries for details about a specific chunk appending details of receipts and transactions to the same chunk data provided by a block

See

https://docs.near.org/api/rpc/block-chunk

Parameters​

NameTypeDescription
chunkIdChunkIdHash of a chunk ID or shard ID

Returns​

Promise<ChunkResult>

Overrides​

Provider.chunk

Defined in​

providers/json-rpc-provider.ts:185


contractCodeChanges​

contractCodeChanges(accountIdArray, blockQuery): Promise<ChangeResult>

Gets contract code changes for a given array of accountIds pass block_id OR finality as blockQuery, not both Note: Change is returned in a base64 encoded WASM file See docs for more info

Parameters​

NameType
accountIdArraystring[]
blockQueryBlockReference

Returns​

Promise<ChangeResult>

Overrides​

Provider.contractCodeChanges

Defined in​

providers/json-rpc-provider.ts:293


contractStateChanges​

contractStateChanges(accountIdArray, blockQuery, keyPrefix?): Promise<ChangeResult>

Gets contract state changes for a given array of accountIds pass block_id OR finality as blockQuery, not both Note: If you pass a keyPrefix it must be base64 encoded See docs for more info

Parameters​

NameTypeDefault value
accountIdArraystring[]undefined
blockQueryBlockReferenceundefined
keyPrefixstring''

Returns​

Promise<ChangeResult>

Overrides​

Provider.contractStateChanges

Defined in​

providers/json-rpc-provider.ts:274


experimental_protocolConfig​

experimental_protocolConfig(blockReference): Promise<NearProtocolConfig>

Gets the protocol config at a block from RPC

Parameters​

NameTypeDescription
blockReferenceBlockReference | { sync_checkpoint: "genesis" }specifies the block to get the protocol config for

Returns​

Promise<NearProtocolConfig>

Overrides​

Provider.experimental_protocolConfig

Defined in​

providers/json-rpc-provider.ts:204


gasPrice​

gasPrice(blockId): Promise<GasPrice>

Returns gas price for a specific block_height or block_hash.

See

https://docs.near.org/api/rpc/gas

Parameters​

NameTypeDescription
blockIdBlockIdBlock hash or height, or null for latest.

Returns​

Promise<GasPrice>

Overrides​

Provider.gasPrice

Defined in​

providers/json-rpc-provider.ts:310


lightClientProof​

lightClientProof(request): Promise<LightClientProof>

Gets a light client execution proof for verifying execution outcomes

See

https://github.com/nearprotocol/NEPs/blob/master/specs/ChainSpec/LightClient.md#light-client-proof

Parameters​

NameType
requestLightClientProofRequest

Returns​

Promise<LightClientProof>

Overrides​

Provider.lightClientProof

Defined in​

providers/json-rpc-provider.ts:213


query​

query<T>(...args): Promise<T>

Query the RPC by passing an RpcQueryRequest

See

https://docs.near.org/api/rpc/contracts

Type parameters​

NameTypeDescription
Textends QueryResponseKindthe shape of the returned query response

Parameters​

NameType
...argsany[]

Returns​

Promise<T>

Overrides​

Provider.query

Defined in​

providers/json-rpc-provider.ts:140


sendJsonRpc​

sendJsonRpc<T>(method, params): Promise<T>

Directly call the RPC specifying the method and params

Type parameters​

Name
T

Parameters​

NameTypeDescription
methodstringRPC method
paramsobjectParameters to the method

Returns​

Promise<T>

Defined in​

providers/json-rpc-provider.ts:320


sendTransaction​

sendTransaction(signedTransaction): Promise<FinalExecutionOutcome>

Sends a signed transaction to the RPC and waits until transaction is fully complete

See

https://docs.near.org/docs/develop/front-end/rpc#send-transaction-await

Parameters​

NameTypeDescription
signedTransactionSignedTransactionThe signed transaction being sent

Returns​

Promise<FinalExecutionOutcome>

Overrides​

Provider.sendTransaction

Defined in​

providers/json-rpc-provider.ts:79


sendTransactionAsync​

sendTransactionAsync(signedTransaction): Promise<FinalExecutionOutcome>

Sends a signed transaction to the RPC and immediately returns transaction hash See docs for more info

Parameters​

NameTypeDescription
signedTransactionSignedTransactionThe signed transaction being sent

Returns​

Promise<FinalExecutionOutcome>

Overrides​

Provider.sendTransactionAsync

Defined in​

providers/json-rpc-provider.ts:90


singleAccessKeyChanges​

singleAccessKeyChanges(accessKeyArray, blockQuery): Promise<ChangeResult>

Gets single access key changes for a given array of access keys pass block_id OR finality as blockQuery, not both See docs for more info

Parameters​

NameType
accessKeyArrayAccessKeyWithPublicKey[]
blockQueryBlockReference

Returns​

Promise<ChangeResult>

Overrides​

Provider.singleAccessKeyChanges

Defined in​

providers/json-rpc-provider.ts:239


status​

status(): Promise<NodeStatusResult>

Gets the RPC's status

See

https://docs.near.org/docs/develop/front-end/rpc#general-validator-status

Returns​

Promise<NodeStatusResult>

Overrides​

Provider.status

Defined in​

providers/json-rpc-provider.ts:69


txStatus​

txStatus(txHash, accountId): Promise<FinalExecutionOutcome>

Gets a transaction's status from the RPC

See

https://docs.near.org/docs/develop/front-end/rpc#transaction-status

Parameters​

NameTypeDescription
txHashstring | Uint8ArrayA transaction hash as either a Uint8Array or a base58 encoded string
accountIdstringThe NEAR account that signed the transaction

Returns​

Promise<FinalExecutionOutcome>

Overrides​

Provider.txStatus

Defined in​

providers/json-rpc-provider.ts:102


txStatusReceipts​

txStatusReceipts(txHash, accountId): Promise<FinalExecutionOutcome>

Gets a transaction's status from the RPC with receipts See docs for more info

Parameters​

NameTypeDescription
txHashstring | Uint8ArrayThe hash of the transaction
accountIdstringThe NEAR account that signed the transaction

Returns​

Promise<FinalExecutionOutcome>

Overrides​

Provider.txStatusReceipts

Defined in​

providers/json-rpc-provider.ts:125


txStatusString​

Private txStatusString(txHash, accountId): Promise<FinalExecutionOutcome>

Parameters​

NameType
txHashstring
accountIdstring

Returns​

Promise<FinalExecutionOutcome>

Defined in​

providers/json-rpc-provider.ts:114


txStatusUint8Array​

Private txStatusUint8Array(txHash, accountId): Promise<FinalExecutionOutcome>

Parameters​

NameType
txHashUint8Array
accountIdstring

Returns​

Promise<FinalExecutionOutcome>

Defined in​

providers/json-rpc-provider.ts:110


validators​

validators(blockId): Promise<EpochValidatorInfo>

Query validators of the epoch defined by the given block id.

See

https://docs.near.org/api/rpc/network#validation-status

Parameters​

NameTypeDescription
blockIdBlockIdBlock hash or height, or null for latest.

Returns​

Promise<EpochValidatorInfo>

Overrides​

Provider.validators

Defined in​

providers/json-rpc-provider.ts:195