EscrowClient

@human-protocol/sdkarrow-up-right


@human-protocol/sdkarrow-up-right / escrow / EscrowClient

Class: EscrowClient

Defined in: escrow.ts:148arrow-up-right

Introduction

This client enables performing actions on Escrow contracts and obtaining information from both the contracts and subgraph.

Internally, the SDK will use one network or another according to the network ID of the runner. To use this client, it is recommended to initialize it using the static build method.

static async build(runner: ContractRunner): Promise<EscrowClient>;

A Signer or a Provider should be passed depending on the use case of this module:

  • Signer: when the user wants to use this model to send transactions calling the contract functions.

  • Provider: when the user wants to use this model to get information from the contracts or subgraph.

Installation

npm

npm install @human-protocol/sdk

yarn

Code example

Signer

Using private key (backend)

Using Wagmi (frontend)

Provider

Extends

Constructors

Constructor

new EscrowClient(runner, networkData): EscrowClient

Defined in: escrow.ts:157arrow-up-right

EscrowClient constructor

Parameters

runner

ContractRunner

The Runner object to interact with the Ethereum network

networkData

NetworkDataarrow-up-right

The network information required to connect to the Escrow contract

Returns

EscrowClient

Overrides

BaseEthersClientarrow-up-right.constructorarrow-up-right

Properties

networkData

networkData: NetworkDataarrow-up-right

Defined in: base.ts:12arrow-up-right

Inherited from

BaseEthersClientarrow-up-right.networkDataarrow-up-right


runner

protected runner: ContractRunner

Defined in: base.ts:11arrow-up-right

Inherited from

BaseEthersClientarrow-up-right.runnerarrow-up-right

Methods

bulkPayOut()

Call Signature

bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete, txOptions?): Promise<void>

Defined in: escrow.ts:802arrow-up-right

This function pays out the amounts specified to the workers and sets the URL of the final results file.

Parameters

escrowAddress

string

Escrow address to payout.

recipients

string[]

Array of recipient addresses.

amounts

bigint[]

Array of amounts the recipients will receive.

finalResultsUrl

string

Final results file URL.

finalResultsHash

string

Final results file hash.

txId

number

Transaction ID.

forceComplete

boolean

Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).

txOptions?

Overrides

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Only Reputation Oracle or admin can call it.

Call Signature

bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, payoutId, forceComplete, txOptions?): Promise<void>

Defined in: escrow.ts:852arrow-up-right

This function pays out the amounts specified to the workers and sets the URL of the final results file.

Parameters

escrowAddress

string

Escrow address to payout.

recipients

string[]

Array of recipient addresses.

amounts

bigint[]

Array of amounts the recipients will receive.

finalResultsUrl

string

Final results file URL.

finalResultsHash

string

Final results file hash.

payoutId

string

Payout ID.

forceComplete

boolean

Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).

txOptions?

Overrides

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Only Reputation Oracle or admin can call it.


cancel()

cancel(escrowAddress, txOptions?): Promise<void>

Defined in: escrow.ts:951arrow-up-right

This function cancels the specified escrow and sends the balance to the canceler.

Parameters

escrowAddress

string

Address of the escrow to cancel.

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Code example

Only Job Launcher or admin can call it.

Returns

Promise<void>


complete()

complete(escrowAddress, txOptions?): Promise<void>

Defined in: escrow.ts:742arrow-up-right

This function sets the status of an escrow to completed.

Parameters

escrowAddress

string

Address of the escrow.

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Only Recording Oracle or admin can call it.


createBulkPayoutTransaction()

createBulkPayoutTransaction(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, payoutId, forceComplete, txOptions?): Promise<TransactionLikeWithNoncearrow-up-right>

Defined in: escrow.ts:1149arrow-up-right

Creates a prepared transaction for bulk payout without immediately sending it.

Parameters

escrowAddress

string

Escrow address to payout.

recipients

string[]

Array of recipient addresses.

amounts

bigint[]

Array of amounts the recipients will receive.

finalResultsUrl

string

Final results file URL.

finalResultsHash

string

Final results file hash.

payoutId

string

Payout ID to identify the payout.

forceComplete

boolean = false

Indicates if remaining balance should be transferred to the escrow creator (optional, defaults to false).

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<TransactionLikeWithNoncearrow-up-right>

Returns object with raw transaction and signed transaction hash

Code example

Only Reputation Oracle or admin can call it.


createFundAndSetupEscrow()

createFundAndSetupEscrow(tokenAddress, amount, jobRequesterId, escrowConfig, txOptions?): Promise<string>

Defined in: escrow.ts:372arrow-up-right

Creates, funds, and sets up a new escrow contract in a single transaction.

Parameters

tokenAddress

string

The ERC-20 token address used to fund the escrow.

amount

bigint

The token amount to fund the escrow with.

jobRequesterId

string

An off-chain identifier for the job requester.

escrowConfig

IEscrowConfigarrow-up-right

Configuration parameters for escrow setup:

  • recordingOracle: Address of the recording oracle.

  • reputationOracle: Address of the reputation oracle.

  • exchangeOracle: Address of the exchange oracle.

  • recordingOracleFee: Fee (in basis points or percentage * 100) for the recording oracle.

  • reputationOracleFee: Fee for the reputation oracle.

  • exchangeOracleFee: Fee for the exchange oracle.

  • manifest: URL to the manifest file.

  • manifestHash: Hash of the manifest content.

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<string>

Returns the address of the escrow created.

Example


fund()

fund(escrowAddress, amount, txOptions?): Promise<void>

Defined in: escrow.ts:545arrow-up-right

This function adds funds of the chosen token to the escrow.

Parameters

escrowAddress

string

Address of the escrow to fund.

amount

bigint

Amount to be added as funds.

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example


getBalance()

getBalance(escrowAddress): Promise<bigint>

Defined in: escrow.ts:1294arrow-up-right

This function returns the balance for a specified escrow address.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<bigint>

Balance of the escrow in the token used to fund it.

Code example


getExchangeOracleAddress()

getExchangeOracleAddress(escrowAddress): Promise<string>

Defined in: escrow.ts:1755arrow-up-right

This function returns the exchange oracle address for a given escrow.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Address of the Exchange Oracle.

Code example


getFactoryAddress()

getFactoryAddress(escrowAddress): Promise<string>

Defined in: escrow.ts:1793arrow-up-right

This function returns the escrow factory address for a given escrow.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Address of the escrow factory.

Code example


getIntermediateResultsHash()

getIntermediateResultsHash(escrowAddress): Promise<string>

Defined in: escrow.ts:1527arrow-up-right

This function returns the intermediate results hash.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Hash of the intermediate results file content.

Code example


getIntermediateResultsUrl()

getIntermediateResultsUrl(escrowAddress): Promise<string>

Defined in: escrow.ts:1489arrow-up-right

This function returns the intermediate results file URL.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Url of the file that store results from Recording Oracle.

Code example


getJobLauncherAddress()

getJobLauncherAddress(escrowAddress): Promise<string>

Defined in: escrow.ts:1679arrow-up-right

This function returns the job launcher address for a given escrow.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Address of the Job Launcher.

Code example


getManifest()

getManifest(escrowAddress): Promise<string>

Defined in: escrow.ts:1413arrow-up-right

This function returns the manifest. Could be a URL or a JSON string.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Url of the manifest.

Code example


getManifestHash()

getManifestHash(escrowAddress): Promise<string>

Defined in: escrow.ts:1375arrow-up-right

This function returns the manifest file hash.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Hash of the manifest file content.

Code example


getRecordingOracleAddress()

getRecordingOracleAddress(escrowAddress): Promise<string>

Defined in: escrow.ts:1641arrow-up-right

This function returns the recording oracle address for a given escrow.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Address of the Recording Oracle.

Code example


getReputationOracleAddress()

getReputationOracleAddress(escrowAddress): Promise<string>

Defined in: escrow.ts:1717arrow-up-right

This function returns the reputation oracle address for a given escrow.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Address of the Reputation Oracle.

Code example


getReservedFunds()

getReservedFunds(escrowAddress): Promise<bigint>

Defined in: escrow.ts:1338arrow-up-right

This function returns the reserved funds for a specified escrow address.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<bigint>

Reserved funds of the escrow in the token used to fund it.

Code example


getResultsUrl()

getResultsUrl(escrowAddress): Promise<string>

Defined in: escrow.ts:1451arrow-up-right

This function returns the results file URL.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Results file url.

Code example


getStatus()

getStatus(escrowAddress): Promise<EscrowStatusarrow-up-right>

Defined in: escrow.ts:1603arrow-up-right

This function returns the current status of the escrow.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<EscrowStatusarrow-up-right>

Current status of the escrow.

Code example


getTokenAddress()

getTokenAddress(escrowAddress): Promise<string>

Defined in: escrow.ts:1565arrow-up-right

This function returns the token address used for funding the escrow.

Parameters

escrowAddress

string

Address of the escrow.

Returns

Promise<string>

Address of the token used to fund the escrow.

Code example


requestCancellation()

requestCancellation(escrowAddress, txOptions?): Promise<void>

Defined in: escrow.ts:997arrow-up-right

This function requests the cancellation of the specified escrow (moves status to ToCancel or finalizes if expired).

Parameters

escrowAddress

string

Address of the escrow to request cancellation.

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Only Job Launcher or admin can call it.


setup()

setup(escrowAddress, escrowConfig, txOptions?): Promise<void>

Defined in: escrow.ts:469arrow-up-right

This function sets up the parameters of the escrow.

Parameters

escrowAddress

string

Address of the escrow to set up.

escrowConfig

IEscrowConfigarrow-up-right

Escrow configuration parameters.

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Only Job Launcher or admin can call it.


storeResults()

Call Signature

storeResults(escrowAddress, url, hash, fundsToReserve, txOptions?): Promise<void>

Defined in: escrow.ts:611arrow-up-right

This function stores the results URL and hash.

Parameters

escrowAddress

string

Address of the escrow.

url

string

Results file URL.

hash

string

Results file hash.

fundsToReserve

bigint

Funds to reserve for payouts

txOptions?

Overrides

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Only Recording Oracle or admin can call it.

Call Signature

storeResults(escrowAddress, url, hash, txOptions?): Promise<void>

Defined in: escrow.ts:647arrow-up-right

This function stores the results URL and hash.

Parameters

escrowAddress

string

Address of the escrow.

url

string

Results file URL.

hash

string

Results file hash.

txOptions?

Overrides

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<void>

Returns void if successful. Throws error if any.

Code example

Only Recording Oracle or admin can call it.


withdraw()

withdraw(escrowAddress, tokenAddress, txOptions?): Promise<IEscrowWithdrawarrow-up-right>

Defined in: escrow.ts:1048arrow-up-right

This function withdraws additional tokens in the escrow to the canceler.

Parameters

escrowAddress

string

Address of the escrow to withdraw.

tokenAddress

string

Address of the token to withdraw.

txOptions?

Overrides = {}

Additional transaction parameters (optional, defaults to an empty object).

Returns

Promise<IEscrowWithdrawarrow-up-right>

Returns the escrow withdrawal data including transaction hash and withdrawal amount. Throws error if any.

Code example

Only Job Launcher or admin can call it.


build()

static build(runner): Promise<EscrowClient>

Defined in: escrow.ts:175arrow-up-right

Creates an instance of EscrowClient from a Runner.

Parameters

runner

ContractRunner

The Runner object to interact with the Ethereum network

Returns

Promise<EscrowClient>

An instance of EscrowClient

Throws

Thrown if the provider does not exist for the provided Signer

Throws

Thrown if the network's chainId is not supported

Last updated