KVStoreClient

@human-protocol/sdkarrow-up-right


@human-protocol/sdkarrow-up-right / kvstore / KVStoreClient

Class: KVStoreClient

Defined in: kvstore.ts:98arrow-up-right

Introduction

This client enables performing actions on KVStore contract and obtaining information from both the contracts and subgraph.

Internally, the SDK will use one network or another according to the network ID of the runner. To use this client, it is recommended to initialize it using the static build method.

static async build(runner: ContractRunner): Promise<KVStoreClient>;

A Signer or a Provider should be passed depending on the use case of this module:

  • Signer: when the user wants to use this model to send transactions calling the contract functions.

  • Provider: when the user wants to use this model to get information from the contracts or subgraph.

Installation

npm

npm install @human-protocol/sdk

yarn

Code example

Signer

Using private key (backend)

Using Wagmi (frontend)

Provider

Extends

Constructors

Constructor

new KVStoreClient(runner, networkData): KVStoreClient

Defined in: kvstore.ts:107arrow-up-right

KVStoreClient constructor

Parameters

runner

ContractRunner

The Runner object to interact with the Ethereum network

networkData

NetworkDataarrow-up-right

The network information required to connect to the KVStore contract

Returns

KVStoreClient

Overrides

BaseEthersClientarrow-up-right.constructorarrow-up-right

Properties

networkData

networkData: NetworkDataarrow-up-right

Defined in: base.ts:12arrow-up-right

Inherited from

BaseEthersClientarrow-up-right.networkDataarrow-up-right


runner

protected runner: ContractRunner

Defined in: base.ts:11arrow-up-right

Inherited from

BaseEthersClientarrow-up-right.runnerarrow-up-right

Methods

get()

get(address, key): Promise<string>

Defined in: kvstore.ts:308arrow-up-right

Gets the value of a key-value pair in the contract.

Parameters

address

string

Address from which to get the key value.

key

string

Key to obtain the value.

Returns

Promise<string>

Value of the key.

Code example

Need to have available stake.


set()

set(key, value, txOptions?): Promise<void>

Defined in: kvstore.ts:170arrow-up-right

This function sets a key-value pair associated with the address that submits the transaction.

Parameters

key

string

Key of the key-value pair

value

string

Value of the key-value pair

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Need to have available stake.


setBulk()

setBulk(keys, values, txOptions?): Promise<void>

Defined in: kvstore.ts:213arrow-up-right

This function sets key-value pairs in bulk associated with the address that submits the transaction.

Parameters

keys

string[]

Array of keys (keys and value must have the same order)

values

string[]

Array of values

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Need to have available stake.


setFileUrlAndHash()

setFileUrlAndHash(url, urlKey, txOptions?): Promise<void>

Defined in: kvstore.ts:256arrow-up-right

Sets a URL value for the address that submits the transaction, and its hash.

Parameters

url

string

URL to set

urlKey

string = 'url'

Configurable URL key. url by default.

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example


build()

static build(runner): Promise<KVStoreClient>

Defined in: kvstore.ts:125arrow-up-right

Creates an instance of KVStoreClient from a runner.

Parameters

runner

ContractRunner

The Runner object to interact with the Ethereum network

Returns

Promise<KVStoreClient>

  • An instance of KVStoreClient

Throws

  • Thrown if the provider does not exist for the provided Signer

Throws

  • Thrown if the network's chainId is not supported

Last updated