/ / 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);
})();