@soroban-dev-kit/codegen
v0.1.0
Published
CLI that generates typed React Query hooks from Soroban CLI TypeScript contract bindings.
Readme
@soroban-dev-kit/codegen
Generates typed useRead<Method>/useWrite<Method> hooks (wrapping
@soroban-dev-kit/react's useReadContract/useWriteContract) from a small JSON
manifest describing a contract's interface.
Why a manifest, not stellar contract bindings typescript output directly
Parsing Soroban CLI's own generated TypeScript bindings would need a real bindings
sample (from the stellar CLI + a deployed contract) to develop and verify against.
A manifest is a small, stable format this package can generate against and test
end-to-end today; parsing real bindings directly is a natural follow-up.
Usage
npx soroban-dev-kit generate --manifest ./contract.json --out ./src/generated.tscontract.json:
{
"contractId": "CADQOBYHA4DQOBYHA4DQOBYHA4DQOBYHA4DQOBYHA4DQOBYHA4DQP5KR",
"methods": [
{ "name": "get_count", "kind": "read" },
{ "name": "balance", "kind": "read", "args": [{ "name": "id", "type": "address" }] },
{
"name": "transfer",
"kind": "write",
"args": [
{ "name": "from", "type": "address" },
{ "name": "to", "type": "address" },
{ "name": "amount", "type": "i128" }
]
}
]
}Each method's kind is "read" (generates a hook around useReadContract) or
"write" (generates a hook around useWriteContract). Supported type values for
args: address, u32, i32, u64, i64, u128, i128, bool, string, symbol, bytes.
