EscrowClient

@human-protocol/sdk / Modules / escrow / EscrowClient

Class: EscrowClient

escrow.EscrowClient

Introduction

This client enables to perform actions on Escrow contracts and obtain 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);

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 in order to send transactions caling the contract functions.

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

Installation

npm

npm install @human-protocol/sdk

yarn

yarn install @human-protocol/sdk

Code example

Signer

Using private key(backend)

import { EscrowClient } from '@human-protocol/sdk';
import { Wallet, providers } from 'ethers';

const rpcUrl = 'YOUR_RPC_URL';
const privateKey = 'YOUR_PRIVATE_KEY'

const provider = new providers.JsonRpcProvider(rpcUrl);
const signer = new Wallet(privateKey, provider);
const escrowClient = await EscrowClient.build(signer);

Using Wagmi(frontend)

import { useSigner, useChainId } from 'wagmi';
import { EscrowClient } from '@human-protocol/sdk';

const { data: signer } = useSigner();
const escrowClient = await EscrowClient.build(signer);

Provider

import { EscrowClient } from '@human-protocol/sdk';
import { providers } from 'ethers';

const rpcUrl = 'YOUR_RPC_URL';

const provider = new providers.JsonRpcProvider(rpcUrl);
const escrowClient = await EscrowClient.build(provider);

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new EscrowClient(runner, networkData): EscrowClient

EscrowClient constructor

Parameters

NameTypeDescription

runner

ContractRunner

The Runner object to interact with the Ethereum network

networkData

NetworkData

-

Returns

EscrowClient

Overrides

BaseEthersClient.constructor

Defined in

escrow.ts:127

Properties

escrowFactoryContract

Private escrowFactoryContract: EscrowFactory

Defined in

escrow.ts:119


networkData

networkData: NetworkData

Inherited from

BaseEthersClient.networkData

Defined in

base.ts:12


runner

Protected runner: ContractRunner

Inherited from

BaseEthersClient.runner

Defined in

base.ts:11

Methods

abort

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

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

Parameters

NameTypeDescription

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 Job Launcher or trusted handler can call it.

import { Wallet, providers } from 'ethers';
import { EscrowClient } from '@human-protocol/sdk';

const rpcUrl = 'YOUR_RPC_URL';
const privateKey = 'YOUR_PRIVATE_KEY'

const provider = new providers.JsonRpcProvider(rpcUrl);
const signer = new Wallet(privateKey, provider);
const escrowClient = await EscrowClient.build(signer);

await escrowClient.abort('0x62dD51230A30401C455c8398d06F85e4EaB6309f');

Defined in

escrow.ts:835


addTrustedHandlers

addTrustedHandlers(escrowAddress, trustedHandlers, txOptions?): Promise<void>

This function sets the status of an escrow to completed.

Parameters

NameTypeDescription

escrowAddress

string

Address of the escrow.

trustedHandlers

string[]

Array of addresses of trusted handlers to add.

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 trusted handler can call it.

import { Wallet, providers } from 'ethers';
import { EscrowClient } from '@human-protocol/sdk';

const rpcUrl = 'YOUR_RPC_URL';
const privateKey = 'YOUR_PRIVATE_KEY'

const provider = new providers.JsonRpcProvider(rpcUrl);
const signer = new Wallet(privateKey, provider);
const escrowClient = await EscrowClient.build(signer);

const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266']
await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers);

Defined in

escrow.ts:883


bulkPayOut

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

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

Parameters

NameTypeDescription

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.

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 a trusted handler can call it.

import { ethers, Wallet, providers } from 'ethers';
import { EscrowClient } from '@human-protocol/sdk';