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

EscrowUtils

Last updated 3 months ago


/ / EscrowUtils

Class: EscrowUtils

Introduction

Utility class for escrow-related operations.

Installation

npm

npm install @human-protocol/sdk

yarn

yarn install @human-protocol/sdk

Code example

Signer

Using private key(backend)

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

const escrowAddresses = new EscrowUtils.getEscrows({
  chainId: ChainId.POLYGON_AMOY
});

Constructors

new EscrowUtils()

Returns

Methods

getEscrow()

This function returns the escrow data for a given address.

This uses Subgraph

Input parameters

enum ChainId {
  ALL = -1,
  MAINNET = 1,
  RINKEBY = 4,
  GOERLI = 5,
  BSC_MAINNET = 56,
  BSC_TESTNET = 97,
  POLYGON = 137,
  POLYGON_MUMBAI = 80001,
  POLYGON_AMOY = 80002,
  MOONBEAM = 1284,
  MOONBASE_ALPHA = 1287,
  AVALANCHE = 43114,
  AVALANCHE_TESTNET = 43113,
  CELO = 42220,
  CELO_ALFAJORES = 44787,
  LOCALHOST = 1338,
}
type EscrowData = {
  id: string;
  address: string;
  amountPaid: string;
  balance: string;
  count: string;
  jobRequesterId: string;
  factoryAddress: string;
  finalResultsUrl?: string;
  intermediateResultsUrl?: string;
  launcher: string;
  manifestHash?: string;
  manifestUrl?: string;
  recordingOracle?: string;
  reputationOracle?: string;
  exchangeOracle?: string;
  status: EscrowStatus;
  token: string;
  totalFundedAmount: string;
  createdAt: string;
};

Parameters

chainId

Network in which the escrow has been deployed

escrowAddress

string

Address of the escrow

Returns

Escrow data

Code example

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

const escrowData = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");

Defined in


getEscrows()

This function returns an array of escrows based on the specified filter parameters.

Input parameters

interface IEscrowsFilter {
  chainId: ChainId;
  launcher?: string;
  reputationOracle?: string;
  recordingOracle?: string;
  exchangeOracle?: string;
  jobRequesterId?: string;
  status?: EscrowStatus;
  from?: Date;
  to?: Date;
  first?: number;
  skip?: number;
  orderDirection?: OrderDirection;
}
enum ChainId {
  ALL = -1,
  MAINNET = 1,
  RINKEBY = 4,
  GOERLI = 5,
  BSC_MAINNET = 56,
  BSC_TESTNET = 97,
  POLYGON = 137,
  POLYGON_MUMBAI = 80001,
  POLYGON_AMOY=80002,
  MOONBEAM = 1284,
  MOONBASE_ALPHA = 1287,
  AVALANCHE = 43114,
  AVALANCHE_TESTNET = 43113,
  CELO = 42220,
  CELO_ALFAJORES = 44787,
  LOCALHOST = 1338,
}
enum OrderDirection {
  ASC = 'asc',
  DESC = 'desc',
}
enum EscrowStatus {
  Launched,
  Pending,
  Partial,
  Paid,
  Complete,
  Cancelled,
}
type EscrowData = {
  id: string;
  address: string;
  amountPaid: string;
  balance: string;
  count: string;
  jobRequesterId: string;
  factoryAddress: string;
  finalResultsUrl?: string;
  intermediateResultsUrl?: string;
  launcher: string;
  manifestHash?: string;
  manifestUrl?: string;
  recordingOracle?: string;
  reputationOracle?: string;
  exchangeOracle?: string;
  status: EscrowStatus;
  token: string;
  totalFundedAmount: string;
  createdAt: string;
};

Parameters

filter

Filter parameters.

Returns

List of escrows that match the filter.

Code example

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

const filters: IEscrowsFilter = {
  status: EscrowStatus.Pending,
  from: new Date(2023, 4, 8),
  to: new Date(2023, 5, 8),
  chainId: ChainId.POLYGON_AMOY
};
const escrowDatas = await EscrowUtils.getEscrows(filters);

Defined in


getStatusEvents()

This function returns the status events for a given set of networks within an optional date range.

This uses Subgraph

Input parameters

enum ChainId {
  ALL = -1,
  MAINNET = 1,
  RINKEBY = 4,
  GOERLI = 5,
  SEPOLIA = 11155111,
  BSC_MAINNET = 56,
  BSC_TESTNET = 97,
  POLYGON = 137,
  POLYGON_MUMBAI = 80001,
  POLYGON_AMOY = 80002,
  MOONBEAM = 1284,
  MOONBASE_ALPHA = 1287,
  AVALANCHE = 43114,
  AVALANCHE_TESTNET = 43113,
  CELO = 42220,
  CELO_ALFAJORES = 44787,
  LOCALHOST = 1338,
  XLAYER_TESTNET = 195,
  XLAYER = 196,
}
enum OrderDirection {
  ASC = 'asc',
  DESC = 'desc',
}
type Status = {
  escrowAddress: string;
  timestamp: string;
  status: string;
};

Parameters

chainId

List of network IDs to query for status events.

statuses?

Optional array of statuses to query for. If not provided, queries for all statuses.

from?

Date

Optional start date to filter events.

to?

Date

Optional end date to filter events.

launcher?

string

Optional launcher address to filter events. Must be a valid Ethereum address.

first?

number

Optional number of transactions per page. Default is 10.

skip?

number

Optional number of transactions to skip. Default is 0.

orderDirection?

Optional order of the results. Default is DESC.

Returns

  • Array of status events with their corresponding statuses.

Code example

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

(async () => {
  const fromDate = new Date('2023-01-01');
  const toDate = new Date('2023-12-31');
  const statusEvents = await EscrowUtils.getStatusEvents(
    [ChainId.POLYGON, ChainId.MAINNET],
    [EscrowStatus.Pending, EscrowStatus.Complete],
    fromDate,
    toDate
  );
  console.log(statusEvents);
})();

Defined in

new EscrowUtils():

static getEscrow(chainId, escrowAddress): Promise<>

Promise<>

static getEscrows(filter): Promise<[]>

Promise<[]>

static getStatusEvents(chainId, statuses?, from?, to?, launcher?, first?, skip?, orderDirection?): Promise<[]>

[]

Promise<[]>

@human-protocol/sdk
@human-protocol/sdk
escrow
EscrowUtils
EscrowUtils
EscrowData
ChainId
EscrowData
escrow.ts:1784
EscrowData
IEscrowsFilter
EscrowData
escrow.ts:1658
StatusEvent
ChainId
EscrowStatus
OrderDirection
StatusEvent
escrow.ts:1882