Skip to main content

Namespace: ui

Functions

addApproveArbitrator

addApproveArbitrator(escrowId, callbacks?): Promise<any>

Opens a modal that checks whether there's an arbitrator proposed or defined for this escrow. If there is no arbitrator proposed or defined, it will display a form for the user to submit their proposed arbitrator's address and fee. If an arbitrator has been proposed, it displays the proposal and allows to either approve it (if it was the other party who proposed the arbitrator) or to change the proposal (if this user sent the original proposal)

Parameters

NameTypeDescription
escrowIdnumberID of the escrow
callbacks?IArbitrationTransactionCallbacksBecause the developer doesn't know what the user's proposal is, they can get the information about what user sent from the broadcasted event, and how the contract processed the proposal in the confirmed event

Returns

Promise<any>

Defined in

ui/render/addApproveArbitrator.ts:20


approveSettlement

approveSettlement(escrowId, callbacks?): Promise<any>

Deprecated

redundant function, will be removed (use settlementOffer() instead)

Parameters

NameType
escrowIdnumber
callbacks?ISettlementApproveTransactionCallbacks

Returns

Promise<any>

Defined in

ui/render/approveSettlement.ts:12


arbitrate

arbitrate(escrowId, callbacks?): Promise<any>

Previously defined/agreed on arbitrator uses this to arbitrate the payment

Parameters

NameTypeDescription
escrowIdnumberID of the escrow to arbitrate
callbacks?IArbitrationTransactionCallbacksBroadcasted and confirmed callbacks provide to the front-end information about what the arbitrator has submitted and how has the contract processed it

Returns

Promise<any>

Defined in

ui/render/arbitrate.ts:15


challenge

challenge(escrowId, callbacks?): Promise<any>

Opens a modal to challenge a payment (either by buyer or seller).

Parameters

NameTypeDescription
escrowIdnumberID of the escrow to challenge
callbacks?IChallengeTransactionCallbacksCode to execute at various steps of the challenge. Confirmed in particular provides information about the escrow after the challenge has been processed by the contract

Returns

Promise<any>

Hash of the challenged transaction

Defined in

ui/render/challenge.ts:13


claim

claim(escrowId, callbacks?): Promise<any>

Displays how much the connected user has in the selected escrow and allows them to claim the escrow. To save everyone's gas costs, it claims balances and fees for all parties that are eligible for it.

Parameters

NameTypeDescription
escrowIdnumberID of the escrow to claim
callbacks?IClaimTransactionCallbacksCode to execute at various stages of the claim transaction. Confirmed callback provides information about the claimed amounts

Returns

Promise<any>

Transaction hash

Defined in

ui/render/claim.ts:14


claimMultiple

claimMultiple(escrowIds, balances, callbacks?): Promise<any>

Displays a modal that summarizes user's balance in all the provided escrows. The balances have to be provided as a separate parameter. Indexer provides an easy way to get inputs for this function

Parameters

NameTypeDescription
escrowIdsnumber[]List of escrow IDs to be claimed. You can get this from indexer's getClaimableEscrows() function
balancesGetResponseUserBalanceBalance broken down by token. You can get this from indexer's getUserBalance() function
callbacks?IClaimTransactionCallbacksCode to execute at various stages of the claim transaction. Confirmed provides information about withdrawn balances (in tokens)

Returns

Promise<any>

Claim Transaction hash

Defined in

ui/render/claimMultiple.ts:19


pay

pay(paymentProps, callbacks?): Promise<any>

Opens a payment modal, which summarizes the escrow parameters for the user (buyer) and displays a button to Pay. If the user is on an incorrect network, it asks them to switch (and provides network configuration automatically).

Ultimately it calls ui.pay() function, which connects user's wallet, checks for the balance in the selected token, asks for approval, and if the address was provided in ENS format, resolves that to ETH address.

Example

// The most simple example of 1 ETH payment with 2 week challenge period and with no arbitrator or a marketplace
await unicrowSdk.ui.pay({
seller: "0xA98135151f8dCd5632A63CC6358f5684c62B041D",
amount: 1,
challengePeriod: ONE_DAY_IN_SEC * 14
}, {
confirmed: (payload) {
// print out payload
}
})

// Output
{
name: "Pay",
transactionHash: "0x965b682d76617355e701ad5e3ece8760f8b0e76815d7d817ee84a8cbdb1f4cd7",
blockNumber: 7956,
paidAt: "2023-01-27T16:31:07.000Z",
escrowId: 593,
arbitrator: null,
arbitratorFee: 0,
buyer: "0xD0244c3B17792390010581D54951ba049dF85861",
seller: "0xA98135151f8dCd5632A63CC6358f5684c62B041D",
challengePeriod: 1209600,
challengePeriodExtension: 1209600,
challengePeriodStart: "2023-01-27T16:31:07.000Z",
challengePeriodEnd: "2023-02-10T16:31:07.000Z",
marketplace: null,
marketplaceFee: 0,
tokenAddress: null,
claimed: false,
consensusBuyer: 0,
consensusSeller: 1,
splitBuyer: 0,
splitSeller: 100,
splitMarketplace: 0,
splitProtocol: 0.69,
amount: "1000000000000000000",
amountBuyer: "0",
amountSeller: "993100000000000000",
amountMarketplace: "0",
amountArbitrator: "0",
amountProtocol: "6900000000000000"
}

// Another example of 1,000 USDT payment with a marketplace and an arbitrator and a different challenge period and extension
await unicrowSdk.ui.pay({
seller: "0xA98135151f8dCd5632A63CC6358f5684c62B041D",
tokenAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
amount: 1000,
challengePeriod: ONE_DAY_IN_SEC * 14,
challengePeriod: ONE_DAY_IN_SEC * 7,
marketplace: "0xf8C03F09b4f53FDc05b57c7846da5F428798f187",
marketplaceFee: 5,
arbitrator: "0x3C86F543e64810E1d843809B2b70a4FDcC3b9B66",
arbitratorFee: 2
}, {
confirmed: (payload) {
// print out payload
}
})

// Output
{
name: "Pay",
transactionHash: "0xb37166392207bbd7e89858606e3b88d11d9d00fb1f508bc0e81dc8a3a990c69f",
blockNumber: 7958,
paidAt: "2023-01-27T16:32:33.000Z",
escrowId: 594,
arbitrator: "0x3C86F543e64810E1d843809B2b70a4FDcC3b9B66",
arbitratorFee: 2,
buyer: "0xD0244c3B17792390010581D54951ba049dF85861",
seller: "0xA98135151f8dCd5632A63CC6358f5684c62B041D",
challengePeriod: 1209600,
challengePeriodExtension: 604800,
challengePeriodStart: "2023-01-27T16:32:33.000Z",
challengePeriodEnd: "2023-02-10T16:32:33.000Z",
marketplace: "0xf8C03F09b4f53FDc05b57c7846da5F428798f187",
marketplaceFee: 5,
tokenAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
claimed: false,
consensusBuyer: 0,
consensusSeller: 1,
splitBuyer: 0,
splitSeller: 100,
splitMarketplace: 5,
splitProtocol: 0.69,
amount: "1000000000",
amountBuyer: "0",
amountSeller: "923100000",
amountMarketplace: "50000000",
amountArbitrator: "20000000",
amountProtocol: "690000"
}

Throws

Error if the user doesn't connect wallet, doesn't approve token spending, doesn't have a a sufficient amount, or if any of the parameters has incorrect format

Parameters

NameTypeDescription
paymentPropsIPaymentPropsPayment details
callbacks?IPayTransactionCallbacksPass code to any of these to be executed when the respective step takes place in the wallet

Returns

Promise<any>

Hash of the payment transaction

Defined in

ui/render/pay.ts:119


refund

refund(escrowId, callbacks?): Promise<any>

Refunds 100% of the buyer payment (all fees are waived), returns transactions' hash. Will display an error if called in an incorrect state (e.g. not by the seller)

Throws

Error if account is not connected or if called in an invalid state (e.g. already claimed / not called by seller)

Parameters

NameTypeDescription
escrowIdnumberid of the escrow to refund
callbacks?IRefundTransactionCallbacks-

Returns

Promise<any>

transaction hash

Defined in

ui/render/refund.ts:14


release

release(escrowId, callbacks?): Promise<string>

Release the escrow to the seller and to all other parties that charge a fee from it. Displays an error if called in an incorrect state (e.g. called by someone else than the buyer, or already claimed)

Throws

If account is not connected or if called in invalid state (e.g. already claimed / not called by the buyer)

Parameters

NameTypeDescription
escrowIdnumberif of the escrow to release
callbacks?IReleaseTransactionCallbacks-

Returns

Promise<string>

transaction hash

Defined in

ui/render/release.ts:14


settlementOffer

settlementOffer(escrowId, callbacks?): Promise<any>

Opens a modal that checks if there is an existing offer to settle the escrow. If not, it will display a form in which the user can submit their settlement offer. If there is an offer, it allows user to accept it (if it was the other party's offer) or to change it (if it was their own)

Parameters

NameTypeDescription
escrowIdnumberID of the escrow
callbacks?ISettlementOfferTransactionCallbacksBroadcasted and confirmed callbacks are particularly useful here because they return information about what the user has submitted and how the contract has processed it

Returns

Promise<any>

Defined in

ui/render/settlementOffer.ts:17