For the complete documentation index, see llms.txt. This page is also available as Markdown.
Single Release Lifecycle
Step by Step Guide to implement Escrow's Single Release Lifecycle
Important
It does not work for a real use case, only for testing purposes. But if you want to implement it, you can use the code below as a reference and customize it to your needs.
Create a Next.js Project#
Start by creating a new Next.js project with TypeScript and Tailwind CSS. In order to make easier the setup, please use the path alias with "@/":
npx create-next-app@latest
Navigate to your project directory:
cd my-trustless-app
Install Trustless Work Blocks#
Install the main library package:
npm
npm install @trustless-work/blocks
Run the CLI Setup
Initialize your project with the Trustless Work CLI:
Wrap your app with the WalletProvider in your layout.tsx:
app/layout.tsx
Example usage in a page:
Add wallet connectivity to your app:
app/page.tsx
Add Helpers
Add helpers to your app:
Add Tanstack Query
Add Tanstack Query to your app:
Add Handle Errors
Add Handle Errors to your app:
Add Providers (If you skipped the init command)
Add Providers to your app:
Add Single Release Escrows Components
Add Single Release Escrows to your app:
Add Single-Multi Release Escrows Components
Add Single-Multi Release Escrows to your app:
Add Escrows by Role Cards
Add Escrows by Role Cards to your app:
Import Actions
In the code, there are some actions commented out. You can uncomment them and import them from the single-release block. See the notes in the escrows by role or by signer components.
Commented Out Code
escrows/escrows-by-role/details/Actions.tsx
Actions Imported
escrows/escrows-by-role/details/Actions.tsx
Manual Provider Setup
Wrap your app with the required providers in this specific order:
app/layout.tsx
Provider Order MattersThe providers must be nested in this exact order for proper functionality.
Example usage in a page:
Now, you are able to interact with the entire escrow lifecycle.
app/page.tsx
All the blocks were added, now use them!You already have all the required blocks to start using the single-release escrow lifecycle.
Final UI
By using these components, you'll be able to completed the entire escrow lifecycle.
Important Usage Advice- This cards components works by role. In the filters section, you can select the role you want to see the escrows for. Based on that, the actions buttons will be rendered.
- Before you start using the UI, you must add the USDC asset to your wallet. If not, you wont be able to interact with Trustless Work.
Wallet Connection Dialog
Show the wallet connection dialog:
Cards by Role
Show the cards by role:
Initialize Escrow Dialog
Show the initialize escrow dialog:
Escrow Details Dialog
Show the escrow details dialog:
The easiest way to implement escrows in blockchain."
return (
<div className="flex items-start justify-start flex-col gap-2 w-full">
{/* You can add the buttons here, using the buttons from the blocks. These actions are conditional based on the escrow flags and the user roles. */}
{hasConditionalButtons && (
<div className="flex flex-col gap-2 w-full">
{/* UpdateEscrowDialog component should be rendered based on the escrow type. It means that if the selectedEscrow.type is "single-release", then the UpdateEscrowDialog (from the single-release block) component should be rendered. If the selectedEscrow.type is "multi-release", then the UpdateEscrowDialog (from the multi-release block) component should be rendered. */}
{/* {shouldShowEditButton && <UpdateEscrowDialog />} */}
{/* Works only with single-release escrows */}
{/* Only appears if the escrow has balance */}
{/* {shouldShowDisputeButton && <DisputeEscrowButton />} */}
{/* Works only with single-release escrows */}
{/* Only appears if the escrow is disputed */}
{/* {shouldShowResolveButton && <ResolveDisputeDialog />} */}
{/* Works only with single-release escrows */}
{/* Only appears if all the milestones are approved */}
{/* {shouldShowReleaseFundsButton && <ReleaseEscrowButton />} */}
</div>
)}
<FundEscrowDialog />
</div>
);
// If you need both types, you should import both versions to update escrow
import { UpdateEscrowDialog } from "../../single-release/update-escrow/dialog/UpdateEscrow";
/* import { UpdateEscrowDialog as UpdateEscrowDialogMultiRelease } from "../../multi-release/update-escrow/dialog/UpdateEscrow"; */
import { FundEscrowDialog } from "../../single-multi-release/fund-escrow/dialog/FundEscrow";
import { DisputeEscrowButton } from "../../single-release/dispute-escrow/button/DisputeEscrow";
import { ResolveDisputeDialog } from "../../single-release/resolve-dispute/dialog/ResolveDispute";
import { ReleaseEscrowButton } from "../../single-release/release-escrow/button/ReleaseEscrow";
return (
<div className="flex items-start justify-start flex-col gap-2 w-full">
{/* You can add the buttons here, using the buttons from the blocks. These actions are conditional based on the escrow flags and the user roles. */}
{hasConditionalButtons && (
<div className="flex flex-col gap-2 w-full">
{/* UpdateEscrowDialog component should be rendered based on the escrow type. It means that if the selectedEscrow.type is "single-release", then the UpdateEscrowDialog (from the single-release block) component should be rendered. If the selectedEscrow.type is "multi-release", then the UpdateEscrowDialog (from the multi-release block) component should be rendered. */}
{shouldShowEditButton && <UpdateEscrowDialog />}
{/* Works only with single-release escrows */}
{shouldShowDisputeButton && <DisputeEscrowButton />}
{/* Works only with single-release escrows */}
{shouldShowResolveButton && <ResolveDisputeDialog />}
{/* Works only with single-release escrows */}
{shouldShowReleaseFundsButton && <ReleaseEscrowButton />}
</div>
)}
<FundEscrowDialog />
</div>
);
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import { ReactQueryClientProvider } from "@/components/tw-blocks/providers/ReactQueryClientProvider";
import { TrustlessWorkProvider } from "@/components/tw-blocks/providers/TrustlessWork";
import { WalletProvider } from "@/components/tw-blocks/wallet-kit/WalletProvider";
import { EscrowProvider } from "@/components/tw-blocks/providers/EscrowProvider";
import { EscrowDialogsProvider } from "@/components/tw-blocks/providers/EscrowDialogsProvider";
import { EscrowAmountProvider } from "@/components/tw-blocks/providers/EscrowAmountProvider";
import { Toaster } from "@/components/ui/sonner";
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
// optional: use geistSans.variable and geistMono.variable
className="antialiased"
>
<ReactQueryClientProvider>
<TrustlessWorkProvider>
<WalletProvider>
<EscrowProvider>
<EscrowDialogsProvider>
<EscrowAmountProvider>
{children}
<Toaster />
</EscrowAmountProvider>
</EscrowDialogsProvider>
</EscrowProvider>
</WalletProvider>
</TrustlessWorkProvider>
</ReactQueryClientProvider>
</body>
</html>
);
}