Human Protocol SDK
v1.1.18
v1.1.18
  • Typescript SDK​
    • Encryption
      • Encryption
      • EncryptionUtils
    • Escrow
      • EscrowClient
      • EscrowUtils
    • KVStore
      • KVStoreClient
    • Staking
      • StakingClient
    • Storage
      • StorageClient
    • Statistics
      • StatisticsClient
  • Python SDK
    • agreement
      • bootstrap
      • measures
      • utils
    • encryption
      • encryption
      • legacy_encryption
      • encryption_utils
    • escrow
      • escrow_client
      • escrow_utils
    • kvstore
      • kvstore_client
    • staking
      • staking_client
      • staking_utils
    • statistics
      • statistics_client
    • storage
      • storage_client
      • storage_utils
    • constants
    • filter
    • utils
Powered by GitBook
On this page
  • Class: KVStoreClient
  • Introduction
  • Installation
  • Code example
  • Hierarchy
  • Table of contents
  • Constructors
  • Properties
  • Methods
  1. Typescript SDK​
  2. KVStore

KVStoreClient

Last updated 1 year ago

/ / / KVStoreClient

Class: KVStoreClient

.KVStoreClient

Introduction

This client enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph.

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

static async build(signerOrProvider: Signer | Provider);

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 in order to send transactions caling the contract functions.

  • Provider: when the user wants to use this model in order 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(signer);

Hierarchy

  • ↳ KVStoreClient

Table of contents

Constructors

Properties

Methods

Constructors

constructor

• new KVStoreClient(signerOrProvider, networkData, gasPriceMultiplier?)

KVStoreClient constructor

Parameters

Name
Type
Description

signerOrProvider

Signer | Provider

The Signer or Provider object to interact with the Ethereum network

networkData

NetworkData

-

gasPriceMultiplier?

number

The multiplier to apply to the gas price

Overrides

Defined in

Properties

contract

• Private contract: KVStore

Defined in


gasPriceMultiplier

• Protected Optional gasPriceMultiplier: number

Inherited from

Defined in


networkData

• networkData: NetworkData

Inherited from

Defined in


signerOrProvider

• Protected signerOrProvider: Signer | Provider

Inherited from

Defined in

Methods

gasPriceOptions

▸ Protected gasPriceOptions(): Promise<Partial<Overrides>>

Adjust the gas price, and return as an option to be passed to a transaction

Returns

Promise<Partial<Overrides>>

Returns the gas price options

Inherited from

Defined in


get

▸ get(address, key): Promise<string>

This function returns the value for a specified key and address.

Parameters

Name
Type
Description

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.

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

const rpcUrl = 'YOUR_RPC_URL';

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

const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');

Defined in


getURL

▸ getURL(address, urlKey?): Promise<string>

This function returns the URL value for the given entity.

Parameters

Name
Type
Default value
Description

address

string

undefined

Address from which to get the URL value.

urlKey

string

'url'

Configurable URL key. url by default.

Returns

Promise<string>

URL value for the given address if exists, and the content is valid

Code example

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

const rpcUrl = 'YOUR_RPC_URL';

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

const url = await kvstoreClient.getURL('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
const linkedinUrl = await kvstoreClient.getURL(
   '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
   'linkedinUrl'
);

Defined in


set

▸ set(key, value): Promise<void>

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

Parameters

Name
Type
Description

key

string

Key of the key-value pair

value

string

Value of the key-value pair

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): Promise<void>

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

Parameters

Name
Type
Description

keys

string[]

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

values

string[]

Array of values

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', 'webhookUrl'];
const values = ['RecordingOracle', 'http://localhost'];
await kvstoreClient.set(keys, values);

Defined in


setURL

▸ setURL(url, urlKey?): Promise<void>

This function sets a URL value for the address that submits the transaction.

Parameters

Name
Type
Default value
Description

url

string

undefined

URL to set

urlKey

string

'url'

Configurable URL key. url by default.

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.setURL('example.com');
await kvstoreClient.setURL('linkedin.com/example', 'linkedinUrl);

Defined in


build

Creates an instance of KVStoreClient from a Signer or Provider.

Parameters

Name
Type
Description

signerOrProvider

Signer | Provider

The Signer or Provider object to interact with the Ethereum network

gasPriceMultiplier?

number

The multiplier to apply to the gas price

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

.

.

.

.

.

▸ Static build(signerOrProvider, gasPriceMultiplier?): Promise<>

Promise<>

@human-protocol/sdk
Modules
kvstore
kvstore
BaseEthersClient
BaseEthersClient
constructor
kvstore.ts:104
kvstore.ts:95
BaseEthersClient
gasPriceMultiplier
base.ts:14
BaseEthersClient
networkData
base.ts:15
BaseEthersClient
signerOrProvider
base.ts:13
BaseEthersClient
gasPriceOptions
base.ts:39
kvstore.ts:311
kvstore.ts:350
kvstore.ts:179
kvstore.ts:220
kvstore.ts:261
KVStoreClient
KVStoreClient
kvstore.ts:127
constructor
contract
gasPriceMultiplier
networkData
signerOrProvider
gasPriceOptions
get
getURL
set
setBulk
setURL
build