Class: PublicClient
PublicClient is a class that allows for interacting with the network via the JSON-RPC API. It provides an abstraction of the connection to =nil;. PublicClient enables using API requests that do not require signing data (or otherwise using one's private key).
Example
import { PublicClient } from '@nilfoundation/niljs';
const client = new PublicClient({
transport: new HttpTransport({
endpoint: "http://127.0.0.1:8529",
}),
shardId: 1,
});
Extends
BaseClient
Constructors
new PublicClient()
new PublicClient(config): PublicClient
Creates an instance of PublicClient.
Parameters
Parameter | Type | Description |
---|---|---|
| The config to be used in the client. See IPublicClientConfig. |
Returns
Overrides
BaseClient.constructor
Defined in
nil/nil.js/src/clients/PublicClient.ts:38
Properties
shardId?
protected optional shardId: number;
The ID of the shard which the client needs to interact with. The shard with this ID will be used in every call made by the client.
Inherited from
BaseClient.shardId
Defined in
nil/nil.js/src/clients/BaseClient.ts:25
transport
protected transport: ITransport;
The ITransport to be used in the client. See ITransport.
Inherited from
BaseClient.transport
Defined in
nil/nil.js/src/clients/BaseClient.ts:18
Methods
call()
call(callArgs, blockNumberOrHash): Promise<`0x${string}`>
Returns the result of the call.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The arguments for the call. |
| `0x${string}` | | The number/hash of the block. |
Returns
Promise
<`0x${string}`>
Defined in
nil/nil.js/src/clients/PublicClient.ts:405
chainId()
chainId(): Promise<number>
Returns the chain ID.
Returns
Promise
<number
>
The chain ID.
Defined in
nil/nil.js/src/clients/PublicClient.ts:361
estimateGasLimit()
estimateGasLimit(): Promise<bigint>
Returns the gas limit.
Returns
Promise
<bigint
>
The gas limit.
Defined in
nil/nil.js/src/clients/PublicClient.ts:351
getBalance()
getBalance(address, blockNumberOrHash): Promise<bigint>
Returns the balance of the given address and at the given block.
Parameters
Parameter | Type | Description |
---|---|---|
| `0x${string}` | The address of the account or contract. |
| `0x${string}` | | The number/hash of the block. |
Returns
Promise
<bigint
>
The balance of the address.
Example
import { PublicClient } from '@nilfoundation/niljs';
const client = new PublicClient({
endpoint: 'http://127.0.0.1:8529'
})
const balance = await client.getBalance(Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), 'latest');
Defined in
nil/nil.js/src/clients/PublicClient.ts:233
getBlockByHash()
getBlockByHash(
hash,
fullTx,
shardId): Promise<Block>
Returns the block with the given hash.