Trustless Work
  • Welcome
    • Why Escrows Matter
    • 🛤️Our Journey so Far
      • 🤔The Problem: Origins of Trustless Work
      • 👾The team comes together
      • 💡The Solution: Escrows
      • 🏆Key Milestones
        • 🌠DraperU Stellar Astro Hacker House: A Pivotal Moment
        • Launching the API V1 at ETH Pura Vida Hackathon
      • 🚀Current Programs
        • 🌟DraperU Embark Program
        • 💻OD Hack Campaigns
      • 🛠️Vertical Development
      • 🔮Future Vision
  • 📌Start Here
    • ☀️About Trustless Work
      • Vision and Mission
      • Team
  • ⚒️Understanding Smart Escrows
    • 🥸Smart Escrow Design
      • What does a Smart Escrow "look like"?
      • Roles in Trustless Work
      • Escrow Lifecycle
        • Initiation Phase
        • Funding Phase
        • Complete phase
        • Approval phase
        • Release phase
        • Dispute Resolution
    • 💵USDC: The Stablecoin Powering Trustless Work
    • 🌟Stellar & Soroban: The Backbone of Trustless Work
  • 💻Developer Resources
    • 🚀Smart Escrow API
    • Quickstart
      • Integration Demo Project
        • Getting Started
        • Entities
        • Configuration
      • dApp locally
      • API Fundamental Code
    • API Reference
      • Introduction
      • Authentication
        • Request Api Key
      • Deploy
        • Initialize Escrow
      • Escrows
        • Schema
        • Fund Escrow
        • Get Escrow by Contract ID
        • Resolve Dispute
        • Change Milestone Status
        • Change Milestone Flag
        • Change Dispute Flag
        • Release Funds
        • Update escrow properties
      • Helpers
        • Set Trustline
        • Send Transaction
        • Get Multiple Escrow Balance
    • 🧰Essential Tools for Developers
      • Stellar Wallets
        • Freighter Wallet
        • Albedo Wallet
        • xBull Wallet
        • Rabet Wallet
        • Lobstr Wallet
        • Hana Wallet
        • Additional Resources
        • Troubleshooting & FAQs
      • How to Get Testnet Tokens
  • 🌍Use Cases by Industry
    • Marketplaces & E-commerce
    • Grants, Bounties, and Hackathons
    • P2P Exchanges and OTC Desks
    • Security Deposits
    • Milestone-based Freelance & Contract Work
    • Crowdfunding & Pre-orders
    • DAO Treasury & Working Group Budgets
    • Education & Online Courses
    • Subscription + Performance-based Retainers
  • 🤖Using the dApp
    • Step 1: Accessing the Trustless Work Dapp and Logging In
    • Step 2: Creating a Profile and Requesting an API Key
    • Step 3: Creating an Escrow
    • Step 4: Funding an Escrow
    • Step 5: Marking a Milestone as Done ✅
    • Step 6: Approving the Milestone
    • Step 7: Releasing the Payment
    • Resolving Disputes
  • 🏴‍☠️Community
    • 🌎Spotlight: Kindfi
    • 🛣️Roadmap: The Journey Ahead
    • Contributor's Guide
    • 📂Open-Source Templates & Developer Tools
  • ✒️Background & Theory
    • 📘Core Concepts & Escrow Glossary
    • 🎒Historical Context
      • 📜Escrow History:
        • 🗿Ancient to Colonial Era
        • 🏦Banking Era (19th - 20th Century)
        • 💻The Digital Era and Online Escrow
      • ⛓️Blockchain Era: Smart Escrows
  • Links
    • ⚒️Trustless Work dApp
    • 🌐Trustless Work Website
    • 📣Telegram Chat
    • 💎Only Dust Profile
    • 👩‍💻Swagger for API
    • 📜Github
  • 📢Appendices
    • Contact and Support
    • Notion for Startups
    • Meru
Powered by GitBook
LogoLogo

Links

  • Website
On this page
  • Core Configuration
  • Fetching
  • Wallet Integration
  • Global State Management
  • Integration TW API
  • Basic Flow
  • Services - Endpoints

Was this helpful?

Export as PDF
  1. Developer Resources
  2. Quickstart

API Fundamental Code

It is important to clarify that the technologies being used are only examples, as provided in our dApp. You can use any other technology you need.

PreviousdApp locallyNextAPI Reference

Last updated 1 day ago

Was this helpful?

Core Configuration

Fetching

In this part, you can use the library of your choice. In TW case, we're using , but you can use whatever you want.

In order to set the .env, please go to:

npm install axios

yarn add axios

pnpm add axios

bun add axios

src\lib\axios.ts

import axios from "axios";

const http = axios.create({
  baseURL: process.env.NEXT_PUBLIC_API_URL || "",
  timeout: 60000, // 1 minute
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${process.env.NEXT_PUBLIC_API_KEY}`,
  },
});

export default http;

Wallet Integration

npm install "@creit.tech/stellar-wallets-kit"

yarn add "@creit.tech/stellar-wallets-kit"

pnpm add "@creit.tech/stellar-wallets-kit"

bun add "@creit.tech/stellar-wallets-kit"

src\lib\stellar-wallet-kit.ts

import {
  StellarWalletsKit,
  WalletNetwork,
} from "@creit.tech/stellar-wallets-kit";
import { WalletNetwork } from "@creit.tech/stellar-wallets-kit";

// KIT Configuration
export const kit: StellarWalletsKit = new StellarWalletsKit({
  network: WalletNetwork.TESTNET,
  selectedWalletId: // wallets that you'd like to add,
  modules: // modules that you'd like to add,
});

// Sign Transaction
interface signTransactionProps {
  unsignedTransaction: string;
  address: string;
}

export const signTransaction = async ({
  unsignedTransaction,
  address,
}: signTransactionProps): Promise<string> => {
  const { signedTxXdr } = await kit.signTransaction(unsignedTransaction, {
    address,
    networkPassphrase: WalletNetwork.TESTNET, // or Mainnet
  });

  return signedTxXdr;
};


Global State Management

npm install zustand

yarn add zustand

pnpm add zustand

bun add zustand

src\components\modules\auth\wallet\hooks\wallet.hook.ts

import { ISupportedWallet } from "@creit.tech/stellar-wallets-kit";
import { kit } from ".lib/stellar-wallet-kit.ts";
import { useGlobalAuthenticationStore } from "@/core/store/data";

export const useWallet = () => {
  const { connectWalletStore, disconnectWalletStore } =
    useGlobalAuthenticationStore(); /* If you're using some global state 
    management, in our case is Zustand */

  const connectWallet = async () => {
    await kit.openModal({
      modalTitle: "Connect to your favorite wallet",
      onWalletSelected: async (option: ISupportedWallet) => {
        kit.setWallet(option.id);

        const { address } = await kit.getAddress();
        const { name } = option;

        connectWalletStore(address, name); /* save the adddress and name's wallet 
        into your state management */
      },
    });
  };

  const disconnectWallet = async () => {
    await kit.disconnect();
    disconnectWalletStore(); /* remove the adddress and name's wallet 
    of your state management */
  };

  const handleConnect = async () => {
    try {
      await connectWallet();
    } catch (error) {
      console.error("Error connecting wallet:", error);
    }
  };

  const handleDisconnect = async () => {
    try {
      if (disconnectWallet) {
        await disconnectWallet();
      }
    } catch (error) {
      console.error("Error disconnecting wallet:", error);
    }
  };

  return {
    connectWallet,
    disconnectWallet,
    handleConnect,
    handleDisconnect,
  };
};

When you already have this part done, you can create some buttons to use the handleConnect and handleDisconnect functions.

Integration TW API

Basic Flow


Services - Endpoints

Flow that must always be executed at each Endpoint except Get Balances

In our case, we're using , a library that simplifies connecting to Stellar-compatible wallets like Freighter. A wallet is necessary because all escrow actions—such as creating, funding, or releasing—require users to sign blockchain transactions (XDR format) with their private keys. Stellar Wallet Kit handles the interaction and signing process securely from the frontend. That said, you’re free to use any wallet that supports XDR signing, as long as it integrates smoothly with your app.

In our case, as we're using library, but you can use whatever you want.

💻
axios
dApp locally
Stellar Wallet Kit
Zustand