Voltar para Documentação

Docs Técnicas

Functions And Entry Points

Every callable function is a contract entrypoint.

O conteúdo abaixo vem das fontes técnicas do repositório e é prerenderizado no site para leitura direta por pessoas, crawlers e agentes.

Every callable function is a contract entrypoint.

Views

python
@view
def is_active() -> bool:
    return self.active

Views are read-only. The verifier rejects storage writes, events, and economic effects in views.

Transactions

python
@tx
def request_loan(lender: Address, principal: u128, rate_ppm: u64):
    require(self.active == False, "loan_already_active")
    self.lender = lender
    self.borrower = ctx.caller
    self.requested_principal = principal
    self.requested_rate_ppm = rate_ppm
    emit LoanRequested(lender, ctx.caller, principal, rate_ppm)

Transactions may mutate storage and produce effects.

Constructors

python
@construct
def initialize(admin: Address):
    self.admin = admin

An @construct entrypoint is the contract constructor. It may mutate storage like a transaction, but it is one-shot: after it succeeds, the runtime rejects any second call. When a contract declares @construct, all other entrypoints are gated until construction succeeds.

@init is accepted as a compatibility alias, but new contracts should use @construct.

Descriptions

@describe("text") can document a contract or an entrypoint for wallet, explorer, and audit UX.

python
@describe("Credit card vault with issuer-funded payments.")
contract CreditCardVault:

    @describe("Pays {merchant} with a signed card intent for {amount}.")
    @tx
    def pay(merchant: Address, amount: u128, nonce: u64, signed_intent: String):
        require(amount > 0, "amount_required")

For functions, {name} placeholders must reference a parameter of that function. {self.field} is accepted as author text, but it is not a protocol proof. AI Audit compares @describe claims with verified effects and can flag mismatches.

Parameters

python
def repay(amount: u128):

Parameter names must be unique.

Returns

python
def principal() -> u128:
    return self.principal_due

Return arity and return type compatibility are verified at compile time.

Overrides

A child contract can replace a function inherited from a base module:

python
@tx
override def mint(amount: u128):
    require(ctx.caller == self.owner, "only_owner")
    require(amount > 0, "amount_must_be_positive")
    self.balances[ctx.caller] = self.balances[ctx.caller] + amount
    self.total = self.total + amount

The override keyword is required. The verifier rejects an override that does not match any base function name, and rejects a child function that shadows a base function without override.

The @tx, @view, or @construct decorator must still appear before override.

Calling the Base Implementation

Inside an override, super.method(args) calls the original base implementation:

python
@tx
override def pause():
    require(ctx.caller == self.owner, "only_owner")
    super.pause()        # delegates to Pausable.pause()

super is only valid inside an override def. The base function name must match the override name. The call is resolved at compile time — there is no dynamic dispatch.

Selectors

Artifacts include a deterministic selector for each entrypoint. Clients may call by name or selector through the ledger API.