Skip to content

Document Soroban contract constructors: declaration, register/register_at args, and recording-auth behavior #2676

Description

@leighmcculloch

What problem does your feature solve?

Soroban contract constructors (the __constructor function generated when a #[contract]/#[contractimpl] struct defines one) have no dedicated documentation anywhere in stellar-docs. They only appear incidentally inside various example-contract pages (tokens.mdx, fungible-token.mdx, liquidity-pool.mdx, non-fungible-token.mdx, complex-account.mdx, delegate-auth.mdx, deployer.mdx), with no explanation of what a constructor is, how to declare one, or how Env::register()/Env::register_at() pass constructor arguments when registering a contract for testing or deployment.

Also undocumented is that constructors run under "recording auth" during registration in tests, so a constructor that calls require_auth() is automatically authorized without needing mock_all_auths() first. This behavior already existed for Wasm contracts, but was inconsistent for native contracts and for register_at until two recent fixes in rs-soroban-sdk: PR #1943 (stellar/rs-soroban-sdk#1943, merged 2026-07-22) fixed native constructors for both register and register_at, following PR #1933 (stellar/rs-soroban-sdk#1933, merged 2026-07-21) which fixed register_at for Wasm constructors. Together these close stellar/rs-soroban-sdk#1738, and as of main in rs-soroban-sdk, register/register_at now uniformly switch to recording auth around the constructor call regardless of Wasm vs native. None of this is captured anywhere in stellar-docs.

What would you like to see?

Perhaps a dedicated section or page describing Soroban contract constructors as a concept could help, covering how to declare one, how register/register_at pass constructor arguments, and the recording-auth behavior during registration. Somewhere under docs/build/smart-contracts/ (for example alongside the getting-started guide, or as part of a "basics" style page near the overview) or under docs/learn/fundamentals/contract-development/ could be a reasonable home, but the best location is worth a second look when this is picked up rather than assuming one now.

What alternatives are there?

A narrower PR, #2666 ("Document constructor auth for register/register_at"), is already in flight. It adds a short note about the recording-auth behavior to docs/build/guides/testing/test-contract-auth.mdx. That PR is useful but scoped only to the auth caveat in that one file, and doesn't address the broader absence of any conceptual documentation of constructors themselves.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions