Skip to content

Set Up Soroban Smart Contract Client Service #13

@Mathews-25

Description

@Mathews-25

Context:
StellarSwipe uses Soroban smart contracts for automated trade execution with risk gates. The backend needs to interact with deployed contracts.

Problem:
Create a service that connects to Soroban RPC, invokes contract methods, and handles transaction submission.

What Done Looks Like:

  • Soroban client service
  • Contract method invocation helpers
  • Transaction simulation before submission
  • Error handling for contract failures
  • Network fee estimation

Folder Structure:

src/
├── soroban/
│   ├── soroban.service.ts
│   ├── soroban.module.ts
│   ├── contracts/
│   │   ├── trade-executor.contract.ts
│   │   └── stake-manager.contract.ts
│   ├── dto/
│   │   └── invoke-contract.dto.ts
│   └── interfaces/
│       └── contract-result.interface.ts

Implementation Guidelines:

  • Use @stellar/stellar-sdk SorobanRpc namespace
  • Configure RPC URL from environment
  • Implement contract invocation wrapper
  • Simulate transactions before submission
  • Parse contract events from results
  • Handle network congestion (Protocol 23 parallel execution)

Key Methods:

  • invokeContract(contractId, method, params)
  • simulateTransaction(tx)
  • getContractEvents(txHash)
  • estimateFees(operation)

Edge Cases:

  • Contract execution failure
  • Insufficient balance for fees
  • Network timeout
  • Invalid contract parameters

Validation:

  • Successfully invoke test contract
  • Simulation detects errors
  • Events parsed correctly
  • Fee estimation accurate

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions