Skip to content

Add a working Stellar JavaScript SDK code example for each public contract function in CONTRACT_API.md #134

Description

@thegreatfeez

Docs — API Reference

Summary

CONTRACT_API.md documents every public function's signature and parameters but gives no code examples. This issue adds a copy-paste-ready JavaScript snippet below each function entry so integrators can call Accord without needing to reverse-engineer the frontend source.

Background

The contract exposes twelve public functions: initialize, create_proposal, approve, revoke, execute, get_proposal, get_proposals_paged, get_owners, get_threshold, get_total_proposals, is_owner, and has_approved. The frontend already calls all of these using @stellar/stellar-sdk — the patterns live in frontend/src/lib/contract.ts. Read-only view functions use simulateTransaction; state-changing functions (initialize, create_proposal, approve, revoke, execute) need a signed transaction submitted via sendTransaction.

What Needs to Be Done

  1. Add a short preamble near the top of docs/CONTRACT_API.md — after the opening two lines — explaining the two call patterns used throughout: simulateTransaction for read-only calls and sendTransaction for state-changing ones. Include the shared setup block (RPC server instantiation, Contract object, network passphrase) once in the preamble so it does not repeat in every snippet.
  2. For each of the five state-changing functions (initialize, create_proposal, approve, revoke, execute), add a JavaScript code block immediately after the existing parameter table showing how to build, simulate-assemble, sign, and submit the transaction using @stellar/stellar-sdk.
  3. For each of the seven read-only functions (get_proposal, get_proposals_paged, get_owners, get_threshold, get_total_proposals, is_owner, has_approved), add a JavaScript code block immediately after the existing description showing how to call the function via simulateTransaction and decode the return value with scValToNative.
  4. Make sure every snippet references the correct argument types that match the Rust signature — for example, nativeToScVal for addresses and amounts, and xdr.ScVal.scvU64 for u64 proposal IDs.

Acceptance Criteria

  • Every public function entry in CONTRACT_API.md has a JavaScript code block directly beneath it.
  • State-changing function examples include build, simulation/assembly, signing, and submission steps.
  • Read-only function examples decode the return value with scValToNative and log or return the result.
  • A shared setup preamble (server, contract, network passphrase) appears once at the top so snippets stay concise.
  • The snippets are consistent with the @stellar/stellar-sdk API used in frontend/src/lib/contract.ts (same import paths and helper functions).

Files to Look At

  • docs/CONTRACT_API.md — add all code examples here, one block per function
  • frontend/src/lib/contract.ts — existing JS call patterns for read-only and state-changing functions

Difficulty: Medium

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions