Skip to content

The new styling applies starting with version 5.2.0. For earlier versions, visit legacy-sdk.humanprotocol.org.

KVStoreUtils

Utility helpers for KVStore-related queries.

Example

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

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

Methods

getKVStoreData()

static getKVStoreData(
   chainId: ChainId, 
   address: string, 
options?: SubgraphOptions): Promise<IKVStore[]>;

This function returns the KVStore data for a given address.

Parameters

Parameter Type Description
chainId ChainId Network in which the KVStore is deployed
address string Address of the KVStore
options? SubgraphOptions Optional configuration for subgraph requests.

Returns

Type Description
IKVStore[] KVStore data

Throws

Type Description
ErrorUnsupportedChainID If the network's chainId is not supported
ErrorInvalidAddress If the address is invalid
Example
const kvStoreData = await KVStoreUtils.getKVStoreData(
  ChainId.POLYGON_AMOY,
  "0x1234567890123456789012345678901234567890"
);
console.log('KVStore data:', kvStoreData);

get()

static get(
   chainId: ChainId, 
   address: string, 
   key: string, 
options?: SubgraphOptions): Promise<string>;

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

Parameters

Parameter Type Description
chainId 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.
options? SubgraphOptions Optional configuration for subgraph requests.

Returns

Type Description
string Value of the key.

Throws

Type Description
ErrorUnsupportedChainID If the network's chainId is not supported
ErrorInvalidAddress If the address is invalid
ErrorKVStoreEmptyKey If the key is empty
Example
const value = await KVStoreUtils.get(
  ChainId.POLYGON_AMOY,
  '0x1234567890123456789012345678901234567890',
  'role'
);
console.log('Value:', value);

getFileUrlAndVerifyHash()

static getFileUrlAndVerifyHash(
   chainId: ChainId, 
   address: string, 
   urlKey?: string, 
options?: SubgraphOptions): Promise<string>;

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

Parameters

Parameter Type Default value Description
chainId ChainId undefined Network in which the KVStore is deployed
address string undefined Address from which to get the URL value.
urlKey string 'url' Configurable URL key. url by default.
options? SubgraphOptions undefined Optional configuration for subgraph requests.

Returns

Type Description
string URL value for the given address if it exists, and the content is valid

Throws

Type Description
ErrorInvalidAddress If the address is invalid
ErrorInvalidHash If the hash verification fails
Error If fetching URL or hash fails
Example
const url = await KVStoreUtils.getFileUrlAndVerifyHash(
  ChainId.POLYGON_AMOY,
  '0x1234567890123456789012345678901234567890'
);
console.log('Verified URL:', url);

getPublicKey()

static getPublicKey(
   chainId: ChainId, 
   address: string, 
options?: SubgraphOptions): Promise<string>;

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

Parameters

Parameter Type Description
chainId ChainId Network in which the KVStore is deployed
address string Address from which to get the public key.
options? SubgraphOptions Optional configuration for subgraph requests.

Returns

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

Throws

Type Description
ErrorInvalidAddress If the address is invalid
ErrorInvalidHash If the hash verification fails
Error If fetching the public key fails
Example
const publicKey = await KVStoreUtils.getPublicKey(
  ChainId.POLYGON_AMOY,
  '0x1234567890123456789012345678901234567890'
);
console.log('Public key:', publicKey);