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
Name | Type | Description |
---|---|---|
escrowId | number | ID of the escrow |
callbacks? | IApproveArbitrationTransactionCallbacks | Because 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
>
Parameters
Name | Type |
---|---|
escrowId | number |
callbacks? | ISettlementApproveTransactionCallbacks |
Returns
Promise
<any
>
Deprecated
redundant function, will be removed (use settlementOffer() instead)
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
Name | Type | Description |
---|---|---|
escrowId | number | ID of the escrow to arbitrate |
callbacks? | IArbitrateTransactionCallbacks | Broadcasted 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
challenge
▸ challenge(escrowId
, callbacks?
): Promise
<any
>
Opens a modal to challenge a payment (either by buyer or seller).
Parameters
Name | Type | Description |
---|---|---|
escrowId | number | ID of the escrow to challenge |
callbacks? | IChallengeTransactionCallbacks | Code 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
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
Name | Type | Description |
---|---|---|
escrowId | number | ID of the escrow to claim |
callbacks? | IClaimTransactionCallbacks | Code to execute at various stages of the claim transaction. Confirmed callback provides information about the claimed amounts |
Returns
Promise
<any
>
Transaction hash
Defined in
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
Name | Type | Description |
---|---|---|
escrowIds | number [] | List of escrow IDs to be claimed. You can get this from indexer's getClaimableEscrows() function |
balances | GetResponseUserBalance | Balance broken down by token. You can get this from indexer's getUserBalance() function |
callbacks? | IClaimTransactionCallbacks | Code 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
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.
*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
Name | Type | Description |
---|---|---|
paymentProps | IPaymentProps | Payment details |
callbacks? | IPayTransactionCallbacks | Pass 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
See
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
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)
Parameters
Name | Type | Description |
---|---|---|
escrowId | number | id of the escrow to refund |
callbacks? | IRefundTransactionCallbacks | - |
Returns
Promise
<any
>
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
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
Name | Type | Description |
---|---|---|
escrowId | number | if 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
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
Name | Type | Description |
---|---|---|
escrowId | number | ID of the escrow |
callbacks? | ISettlementOfferTransactionCallbacks | Broadcasted 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
>