Human Protocol SDK
v4.1.0
v4.1.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 days ago


/ / EscrowUtils

Class: EscrowUtils

Defined in:

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,
  SEPOLIA = 11155111,
  BSC_MAINNET = 56,
  BSC_TESTNET = 97,
  POLYGON = 137,
  POLYGON_AMOY = 80002,
  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");

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,
  SEPOLIA = 11155111,
  BSC_MAINNET = 56,
  BSC_TESTNET = 97,
  POLYGON = 137,
  POLYGON_AMOY=80002,
  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);

getPayouts()

This function returns the payouts for a given set of networks.

This uses Subgraph

Input parameters Fetch payouts from the subgraph.

Parameters

filter

Filter parameters.

Returns

List of payouts matching the filters.

Code example

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

const payouts = await EscrowUtils.getPayouts({
  chainId: ChainId.POLYGON,
  escrowAddress: '0x1234567890123456789012345678901234567890',
  recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
  from: new Date('2023-01-01'),
  to: new Date('2023-12-31')
});
console.log(payouts);

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,
  SEPOLIA = 11155111,
  BSC_MAINNET = 56,
  BSC_TESTNET = 97,
  POLYGON = 137,
  POLYGON_AMOY = 80002,
  LOCALHOST = 1338,
}
enum OrderDirection {
  ASC = 'asc',
  DESC = 'desc',
}
type Status = {
  escrowAddress: string;
  timestamp: string;
  status: string;
};

Parameters

filter

Filter parameters.

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: ChainId.POLYGON,
    statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
    from: fromDate,
    to: toDate
  });
  console.log(statusEvents);
})();

new EscrowUtils():

static getEscrow(chainId, escrowAddress): Promise<>

Defined in:

Promise<>

static getEscrows(filter): Promise<[]>

Defined in:

Promise<[]>

static getPayouts(filter): Promise<[]>

Defined in:

Promise<[]>

static getStatusEvents(filter): Promise<[]>

Defined in:

Promise<[]>

@human-protocol/sdk
@human-protocol/sdk
escrow
escrow.ts:1565
EscrowUtils
EscrowUtils
EscrowData
escrow.ts:1780
ChainId
EscrowData
EscrowData
escrow.ts:1662
IEscrowsFilter
EscrowData
Payout
escrow.ts:1950
IPayoutFilter
Payout
StatusEvent
escrow.ts:1859
IStatusEventFilter
StatusEvent