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: KVStoreUtils
  • Introduction
  • Installation
  • Code example
  • Constructors
  • Methods
  1. Typescript SDK
  2. KVStore

KVStoreUtils

Last updated 3 months ago


/ / KVStoreUtils

Class: KVStoreUtils

Introduction

Utility class for KVStore-related operations.

Installation

npm

npm install @human-protocol/sdk

yarn

yarn install @human-protocol/sdk

Code example

Signer

Using private key (backend)

import { ChainId, KVStoreUtils } from '@human-protocol/sdk';

const KVStoreAddresses = await KVStoreUtils.getKVStoreData(
  ChainId.POLYGON_AMOY,
  "0x1234567890123456789012345678901234567890"
);

Constructors

new KVStoreUtils()

Returns

Methods

get()

static get(chainId, address, key): Promise<string>

Gets the value of a key-value pair in the KVStore using the subgraph.

Parameters

chainId

Network in which the KVStore is deployed

address

string

Address from which to get the key value.

key

string

Key to obtain the value.

Returns

Promise<string>

Value of the key.

Throws

  • Thrown if the network's chainId is not supported

Throws

  • Thrown if the Address sent is invalid

Throws

  • Thrown if the key is empty

Code example

import { ChainId, KVStoreUtils } from '@human-protocol/sdk';

const chainId = ChainId.POLYGON_AMOY;
const address = '0x1234567890123456789012345678901234567890';
const key = 'role';

const value = await KVStoreUtils.get(chainId, address, key);
console.log(value);

Defined in


getFileUrlAndVerifyHash()

static getFileUrlAndVerifyHash(chainId, address, urlKey): Promise<string>

Gets the URL value of the given entity, and verifies its hash.

Parameters

chainId

Network in which the KVStore is deployed

address

string

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 it exists, and the content is valid

Code example

import { ChainId, KVStoreUtils } from '@human-protocol/sdk';

const chainId = ChainId.POLYGON_AMOY;
const address = '0x1234567890123456789012345678901234567890';

const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
console.log(url);

Defined in


getKVStoreData()

This function returns the KVStore data for a given address.

Parameters

chainId

Network in which the KVStore is deployed

address

string

Address of the KVStore

Returns

KVStore data

Throws

  • Thrown if the network's chainId is not supported

Throws

  • Thrown if the Address sent is invalid

Code example

import { ChainId, KVStoreUtils } from '@human-protocol/sdk';

const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
console.log(kvStoreData);

Defined in


getPublicKey()

static getPublicKey(chainId, address): Promise<string>

Gets the public key of the given entity, and verifies its hash.

Parameters

chainId

Network in which the KVStore is deployed

address

string

Address from which to get the public key.

Returns

Promise<string>

Public key for the given address if it exists, and the content is valid

Code example

import { ChainId, KVStoreUtils } from '@human-protocol/sdk';

const chainId = ChainId.POLYGON_AMOY;
const address = '0x1234567890123456789012345678901234567890';

const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
console.log(publicKey);

Defined in

new KVStoreUtils():

static getKVStoreData(chainId, address): Promise<[]>

Promise<[]>

@human-protocol/sdk
@human-protocol/sdk
kvstore
KVStoreUtils
KVStoreUtils
ChainId
kvstore.ts:389
ChainId
kvstore.ts:436
IKVStore
ChainId
IKVStore
kvstore.ts:337
ChainId
kvstore.ts:496