Build with YBZ

Integrate trustless escrow into your dApp with our comprehensive SDK and smart contract APIs.

Quick Start

Quick Start

Get started with YBZ in minutes. Follow these simple steps to integrate escrow into your application.

1

Install SDK

Install the YBZ SDK via npm or yarn

npm install @ybz/sdk
2

Initialize

Connect to the YBZ contract

const ybz = new YBZ(...)
3

Create Deal

Initialize your first escrow

await createDeal({...})
4

Monitor

Listen to contract events

on('DealCreated', ...)

Integration Options

Choose the integration method that best fits your stack β€” from direct contract calls to high-level SDKs.

Smart Contract

Direct integration with Ethers.js or Web3.js for maximum control and flexibility.

  • Full contract access
  • Event listeners
  • No dependencies
View ABI
Recommended

JavaScript SDK

High-level TypeScript SDK with built-in error handling and type safety.

  • TypeScript support
  • React hooks included
  • Auto gas estimation
View Docs

Query API

Query historical deal data with GraphQL via The Graph subgraph.

  • Historical data
  • GraphQL queries
  • Fast indexing
Explore API

Code Examples

See how easy it is to integrate YBZ escrow into your application with these real-world examples.

createDealETH.js
import { ethers } from 'ethers';
import YBZCore from './YBZCore.json';

const CONTRACT_ADDRESS = '0xAe1D3Af...Ec15611';

async function createDeal() {
  const provider = new ethers.providers.Web3Provider(window.ethereum);
  const signer = provider.getSigner();
  const contract = new ethers.Contract(CONTRACT_ADDRESS, YBZCore.abi, signer);

  const seller = '0x...'; // Seller address
  const amount = ethers.utils.parseEther('1.0'); // 1 ETH
  const acceptWindow = 86400; // 24 hours
  const submitWindow = 604800; // 7 days
  const confirmWindow = 259200; // 3 days
  
  const tx = await contract.createDealETH(
    seller,
    acceptWindow,
    submitWindow,
    confirmWindow,
    ethers.constants.AddressZero, // No arbiter
    '',  // No description
    { value: amount }
  );
  
  const receipt = await tx.wait();
  console.log('Deal created:', receipt);
}
acceptDeal.js
async function acceptDeal(dealId) {
  const provider = new ethers.providers.Web3Provider(window.ethereum);
  const signer = provider.getSigner();
  const contract = new ethers.Contract(CONTRACT_ADDRESS, YBZCore.abi, signer);

  // Accept the deal as seller
  const tx = await contract.acceptDeal(dealId);
  await tx.wait();
  
  console.log(`Deal ${dealId} accepted`);
}
submitWork.js
async function submitWork(dealId, proofHash) {
  const provider = new ethers.providers.Web3Provider(window.ethereum);
  const signer = provider.getSigner();
  const contract = new ethers.Contract(CONTRACT_ADDRESS, YBZCore.abi, signer);

  // Submit work proof (IPFS hash)
  const tx = await contract.submitWork(dealId, proofHash);
  await tx.wait();
  
  console.log(`Work submitted for deal ${dealId}`);
}
listenEvents.js
async function listenToEvents() {
  const provider = new ethers.providers.Web3Provider(window.ethereum);
  const contract = new ethers.Contract(CONTRACT_ADDRESS, YBZCore.abi, provider);

  // Listen for DealCreated events
  contract.on('DealCreated', (dealId, buyer, seller, amount, token) => {
    console.log('New deal created:', {
      dealId: dealId.toString(),
      buyer,
      seller,
      amount: ethers.utils.formatEther(amount),
      token
    });
  });

  // Listen for DealAccepted events
  contract.on('DealAccepted', (dealId, seller) => {
    console.log(`Deal ${dealId} accepted by ${seller}`);
  });
}

Smart Contract Reference

Complete reference of YBZ Core contract functions, events, and view methods.

Core Functions

Function Description Access
createDealETH() Create a new escrow deal with ETH Public
createDealERC20() Create a new escrow deal with ERC20 token Public
acceptDeal() Seller accepts the deal Seller
submitWork() Seller submits work proof Seller
approveDeal() Buyer approves completed work Buyer
raiseDispute() Either party raises a dispute Public
resolveDispute() Arbiter resolves the dispute Arbiter

Events

Event Emitted When
DealCreated New escrow deal is created
DealAccepted Seller accepts the deal
WorkSubmitted Seller submits work proof
DealApproved Buyer approves the work
DisputeRaised A dispute is raised
DisputeResolved Arbiter resolves the dispute

Security Best Practices

Follow these guidelines to build secure and reliable integrations with YBZ.

Input Validation

  • β€’ Validate all addresses before creating deals
  • β€’ Ensure time windows are within allowed ranges
  • β€’ Check deal amount meets minimum requirements ($20 USD)
  • β€’ Verify token addresses are supported stablecoins

Error Handling

  • β€’ Always use try-catch blocks for contract calls
  • β€’ Parse revert reasons for user-friendly messages
  • β€’ Implement retry logic for network failures
  • β€’ Log errors for debugging and monitoring

Gas Optimization

  • β€’ Use gas estimation before transactions
  • β€’ Monitor gas prices for optimal timing
  • β€’ Batch operations when possible
  • β€’ Consider Layer 2 for lower fees

Testing Strategy

  • β€’ Test on testnet before mainnet deployment
  • β€’ Simulate various deal scenarios
  • β€’ Test dispute and timeout edge cases
  • β€’ Verify event listeners work correctly

Ready to Build?

Join our developer community and start integrating trustless escrow into your dApp today.