Skip to content

[Bindings] Generate TypeScript Bindings for Crowdfunding Collective Contract #290

@aguilar1x

Description

@aguilar1x

🎯 Objective

Generate TypeScript bindings for the Crowdfunding Collective Contract using the Stellar CLI to provide type-safe contract interactions in the StarShop Frontend application.

c

🏗 Implementation Steps

1. Contract Deployment

# Install the compiled contract
stellar contract upload \
    --source-account <identity or secret key> \
    --network testnet \
    --wasm ./target/wasm32v1-none/release/crowdfunding_collective.wasm

# Deploy a contract instance
stellar contract deploy \
    --source-account <identity or secret key> \
    --network testnet \
    --wasm-hash <wasm_hash_from_install_step>

2. Generate TypeScript Bindings

stellar contract bindings typescript \
    --network testnet \
    --id <contract_address_from_deploy_step> \
    --output-dir ./packages/crowdfunding_collective \
    --overwrite

3. Build Bindings Package

cd packages/crowdfunding_collective
npm install
npm run build
cd ../..

4. Add to Frontend Dependencies

npm install file:./packages/crowdfunding_collective

5. Create Contract Client

// src/lib/contracts/crowdfunding_collective.ts
import * as Client from "crowdfunding_collective";
import { PUBLIC_STELLAR_RPC_URL } from "$env/static/public";

export default new Client.Client({
  ...Client.networks.testnet,
  rpcUrl: PUBLIC_STELLAR_RPC_URL,
});

🗂 Expected Bindings Structure

// Generated types and functions
- initialize(admin: Address): void
- create_product(creator: Address, name: String, description: String, funding_goal: u64, deadline: u64, reward_tiers: Vec<RewardTier>, milestones: Vec<Milestone>): u32
- contribute(contributor: Address, product_id: u32, amount: u64): void
- distribute_funds(caller: Address, product_id: u32): void
- refund_contributors(caller: Address, product_id: u32): void
- claim_reward(contributor: Address, product_id: u32): void
- update_milestone(creator: Address, product_id: u32, milestone_id: u32): void
- get_product(product_id: u32): Product
- get_contributions(product_id: u32): Vec<Contribution>
- get_milestones(product_id: u32): Vec<Milestone>
- get_reward_tiers(product_id: u32): Vec<RewardTier>
- get_product_status(product_id: u32): ProductStatus

✅ Acceptance Criteria

  • Contract successfully deployed to testnet
  • TypeScript bindings generated and built
  • Bindings package added to frontend dependencies
  • Contract client created and exported
  • All contract functions properly typed
  • Integration tests pass

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions