Skip to main content

Namespace: ui

Functions

addApproveArbitrator

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

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?IApproveArbitrationTransactionCallbacksBecause 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<string>

Defined in

ui/render/addApproveArbitrator.ts:20


approveSettlement

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

Parameters

NameType
escrowIdnumber
callbacks?ISettlementApproveTransactionCallbacks

Returns

Promise<string>

Deprecated

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

Defined in

ui/render/approveSettlement.ts:12


arbitrate

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

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

Parameters

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

Returns

Promise<string>

Defined in

ui/render/arbitrate.ts:12


challenge

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

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<string>

Hash of the challenged transaction

Defined in

ui/render/challenge.ts:13


claim

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

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<string>

Transaction hash

Defined in

ui/render/claim.ts:15


claimMultiple

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

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<string>

Claim Transaction hash

Defined in

ui/render/claimMultiple.ts:20


pay

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

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.

*NOTE: There's a bug here where if the user opens the modal with one account and changes a wallet account while the modal is opened, it submits the original user's address as a buyer's address. To be fixed soon

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<string>

Hash of the payment transaction

See

core.pay

Example

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

// Console output
{
transactionHash: "0xf7d347866aaa583f7a8e63457f4afed85f40932c35ac8ffafc2a1c1dc31b19f6",
blockNumber: 252780689,
paidAt: "2024-09-12T15:07:45.000Z",
escrowId: 2,
arbitrator: null,
arbitratorFee: 0,
buyer: "0x8A62e7F471ad5B5081d4A864580edd944525D1D8",
seller: "0xf463b32cad657fe03921014d99490A0a58290560",
challengePeriod: 1209600,
challengePeriodExtension: 1209600,
challengePeriodStart: "2024-09-12T15:07:45.000Z",
challengePeriodEnd: "2024-09-26T15:07:45.000Z",
marketplace: null,
marketplaceFee: 0,
tokenAddress: null,
paymentReference: "",
claimed: false,
consensusBuyer: 0,
consensusSeller: 1,
splitBuyer: 0,
splitSeller: 100,
splitMarketplace: 0,
splitProtocol: 0.69,
amount: "100000000000000000",
amountBuyer: "0",
amountSeller: "99310000000000000",
amountMarketplace: "0",
amountArbitrator: "0",
amountProtocol: "690000000000000"
}

// Another example using all the available payment parameters:
// - tokenAddress to send 100 USDT
// - setting a different buyer
// - a marketplace and an arbitrator with fees
// - different challenge period and challenge period extension
// - adding a payment reference
await Unicrow.ui.pay({
seller: "0xf463b32cad657fe03921014d99490A0a58290560",
tokenAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
amount: 100,
buyer: "0xF257DD5731A679E6642FCd9c53e4e26A1206527e",
arbitrator: "0x59f56CFC88E5660b7D68C4797c6484168eC8E068",
arbitratorFee: 2,
marketplace: "0x696207De45d897d5a353af3c45314a2F852d5B63",
marketplaceFee: 10,
challengePeriod: 86400 * 14,
challengePeriodExtension: 86400 * 7,
paymentReference: "order #1337"
}, {
confirmed: (payload) {
// print out payload
}
})

// Output
{
transactionHash: "0x51766a44fb247f33e6caf31dbe01579e100dd0b96020c78358b263d86c30c96d",
blockNumber: 252783397,
paidAt: "2024-09-12T15:19:14.000Z",
escrowId: 3,
arbitrator: "0x59f56CFC88E5660b7D68C4797c6484168eC8E068",
arbitratorFee: 2,
buyer: "0xF257DD5731A679E6642FCd9c53e4e26A1206527e",
seller: "0xf463b32cad657fe03921014d99490A0a58290560",
challengePeriod: 1209600,
challengePeriodExtension: 604800,
challengePeriodStart: "2024-09-12T15:19:14.000Z",
challengePeriodEnd: "2024-09-26T15:19:14.000Z",
marketplace: "0x696207De45d897d5a353af3c45314a2F852d5B63",
marketplaceFee: 10,
tokenAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
paymentReference: "order #1337",
claimed: false,
consensusBuyer: 0,
consensusSeller: 1,
splitBuyer: 0,
splitSeller: 100,
splitMarketplace: 10,
splitProtocol: 0.69,
amount: "100000000",
amountBuyer: "0",
amountSeller: "87310000",
amountMarketplace: "10000000",
amountArbitrator: "2000000",
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

Defined in

ui/render/pay.ts:128


refund

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

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)

Parameters

NameTypeDescription
escrowIdnumberid of the escrow to refund
callbacks?IRefundTransactionCallbacks-

Returns

Promise<string>

transaction hash

Throws

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

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)

Parameters

NameTypeDescription
escrowIdnumberif of the escrow to release
callbacks?IReleaseTransactionCallbacks-

Returns

Promise<string>

transaction hash

Throws

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

Defined in

ui/render/release.ts:14


settlementOffer

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

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<string>

Defined in

ui/render/settlementOffer.ts:17