Human Protocol SDK
v4.0.0
v4.0.0
  • Typescript SDK
    • Encryption
      • Encryption
      • EncryptionUtils
    • Escrow
      • EscrowClient
      • EscrowUtils
    • KVStore
      • KVStoreClient
      • KVStoreUtils
    • Staking
      • StakingClient
    • Operator
      • OperatorUtils
    • Storage
      • StorageClient
    • Statistics
      • StatisticsClient
    • Transaction
      • TransactionUtils
  • Python SDK
    • agreement
      • bootstrap
      • measures
      • utils
    • encryption
      • encryption
      • legacy_encryption
      • encryption_utils
    • escrow
      • escrow_client
      • escrow_utils
    • kvstore
      • kvstore_client
      • kvstore_utils
    • staking
      • staking_client
      • staking_utils
    • operator
      • operator_utils
    • statistics
      • statistics_client
    • storage
      • storage_client
      • storage_utils
    • transaction
      • transaction_utils
    • constants
    • filter
    • utils
  • CHANGELOG
Powered by GitBook
On this page
  • Class: KVStoreClient
  • Introduction
  • Installation
  • Code example
  • Extends
  • Constructors
  • Properties
  • Methods
  1. Typescript SDK
  2. KVStore

KVStoreClient

Last updated 3 months ago


/ / KVStoreClient

Class: KVStoreClient

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

yarn install @human-protocol/sdk

Code example

Signer

Using private key (backend)

import { KVStoreClient } from '@human-protocol/sdk';
import { Wallet, providers } from 'ethers';

const rpcUrl = 'YOUR_RPC_URL';
const privateKey = 'YOUR_PRIVATE_KEY';

const provider = new providers.JsonRpcProvider(rpcUrl);
const signer = new Wallet(privateKey, provider);
const kvstoreClient = await KVStoreClient.build(signer);

Using Wagmi (frontend)

import { useSigner, useChainId } from 'wagmi';
import { KVStoreClient } from '@human-protocol/sdk';

const { data: signer } = useSigner();
const kvstoreClient = await KVStoreClient.build(signer);

Provider

import { KVStoreClient } from '@human-protocol/sdk';
import { providers } from 'ethers';

const rpcUrl = 'YOUR_RPC_URL';

const provider = new providers.JsonRpcProvider(rpcUrl);
const kvstoreClient = await KVStoreClient.build(provider);

Extends

Constructors

new KVStoreClient()

KVStoreClient constructor

Parameters

runner

ContractRunner

The Runner object to interact with the Ethereum network

networkData

The network information required to connect to the KVStore contract

Returns

Overrides

Defined in

Properties

networkData

Inherited from

Defined in


runner

protected runner: ContractRunner

Inherited from

Defined in

Methods

set()

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

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.

import { Wallet, providers } from 'ethers';
import { KVStoreClient } from '@human-protocol/sdk';

const rpcUrl = 'YOUR_RPC_URL';
const privateKey = 'YOUR_PRIVATE_KEY';

const provider = new providers.JsonRpcProvider(rpcUrl);
const signer = new Wallet(privateKey, provider);
const kvstoreClient = await KVStoreClient.build(signer);

await kvstoreClient.set('Role', 'RecordingOracle');

Defined in


setBulk()

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

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.

import { Wallet, providers } from 'ethers';
import { KVStoreClient } from '@human-protocol/sdk';

const rpcUrl = 'YOUR_RPC_URL';
const privateKey = 'YOUR_PRIVATE_KEY';

const provider = new providers.JsonRpcProvider(rpcUrl);
const signer = new Wallet(privateKey, provider);
const kvstoreClient = await KVStoreClient.build(signer);

const keys = ['role', 'webhook_url'];
const values = ['RecordingOracle', 'http://localhost'];
await kvstoreClient.setBulk(keys, values);

Defined in


setFileUrlAndHash()

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

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

import { Wallet, providers } from 'ethers';
import { KVStoreClient } from '@human-protocol/sdk';

const rpcUrl = 'YOUR_RPC_URL';
const privateKey = 'YOUR_PRIVATE_KEY';

const provider = new providers.JsonRpcProvider(rpcUrl);
const signer = new Wallet(privateKey, provider);
const kvstoreClient = await KVStoreClient.build(signer);

await kvstoreClient.setFileUrlAndHash('example.com');
await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url');

Defined in


build()

Creates an instance of KVStoreClient from a runner.

Parameters

runner

ContractRunner

The Runner object to interact with the Ethereum network

Returns

  • 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

Defined in

new KVStoreClient(runner, networkData):

.

networkData:

.

.

static build(runner): Promise<>

Promise<>

@human-protocol/sdk
@human-protocol/sdk
kvstore
BaseEthersClient
KVStoreClient
NetworkData
KVStoreClient
BaseEthersClient
constructor
kvstore.ts:108
NetworkData
BaseEthersClient
networkData
base.ts:12
BaseEthersClient
runner
base.ts:11
kvstore.ts:171
kvstore.ts:214
kvstore.ts:257
KVStoreClient
KVStoreClient
kvstore.ts:126