Page cover

Creating a Tokenized Service (via SDK)

Let’s walk through a simple code example using a hypothetical JavaScript SDK to create a new service listing and then handle a purchase. This example assumes the existence of a cre8-sdk package that abstracts the API and blockchain interactions

// Import the CRE8 SDK (assume it's installed from npm)
const Cre8SDK = require('cre8-sdk');

// Initialize SDK (could include network config, API keys, etc.)
const cre8 = new Cre8SDK({
    network: 'mainnet-beta',  // Solana network
});

// 1. Authenticate (here using a wallet private key for simplicity)
await cre8.auth.loginWithPrivateKey(process.env.SOLANA_PRIVATE_KEY);
// In a real app, you might use cre8.auth.loginWithWallet(wallet) for wallet adapter integration

// 2. Create a new service listing
let newListing = await cre8.listings.create({
    title: "Logo Design Package",
    description: "Professional logo design with 3 revisions included. Delivered in 7 days.",
    price: 50,
    currency: "USDC",         // using USDC as the currency for price
    category: "Design",
    delivery_time: 7,         // days
});
console.log("New listing created with ID:", newListing.id);
console.log("Service Token Mint Address:", newListing.tokenMint);

// 3. Query the marketplace for listings (e.g., to display or search)
let designListings = await cre8.marketplace.search({ category: "Design", sortBy: "price_asc" });
console.log(`Found ${designListings.length} design services.`);

// 4. Simulate a buyer purchasing the service
// (In a real scenario, buyer would use their own instance/auth of the SDK)
let order = await cre8.orders.buy({
    listingId: newListing.id,
    buyerWallet: buyerWalletAddress, // assuming buyerWalletAddress is known or same user for demo
    paymentToken: "USDC"
});
console.log("Purchase initiated, escrow account:", order.escrowAccount);

// 5. Seller marks the service as delivered
await cre8.orders.markDelivered({ orderId: order.id });
// 6. Buyer confirms the delivery
await cre8.orders.confirmDelivery({ orderId: order.id });

console.log("Order completed. Funds released to seller.");

In this snippet:

  • We logged in (for scripting, using a private key directly; for real apps, use secure wallet integrations).

  • Created a listing for a logo design service. The SDK call likely handled minting the SPL token for the service and registering the listing on the marketplace.

  • Searched the marketplace for demonstration (this could be used to build a listing page in a UI).

  • Simulated a purchase: The buy method would internally create the escrow transaction (transferring funds from buyer to the escrow contract and reserving the token).

  • Marked delivery and confirmation, which triggers the escrow release. In practice, the buyer’s confirmation might happen in their app, not via the seller’s SDK instance, but shown here sequentially for completeness.

Last updated