Skip to content

Writing code

Writing and checking your contract: the SmartC editor helps you while you type, compiles the contract into the code that runs on the chain, and warns you about common mistakes and about running out of gas before you ever deploy.

You write the contract in SmartC, a C dialect for Signum smart contracts. The blockchain doesn’t run SmartC itself; it runs AT assembly (the CIYAM AT virtual machine). Compile turns your .smart.c file into an assembly file, .asm, next to it.

While you type, the Studio checks the contract three ways:

  • Compiler errors — the code doesn’t compile. Shown as red markers and in the editor toolbar.
  • Lint — the code compiles but has a known weak spot, such as sending SIGNA without checking the balance. Shown as warnings, each with a hint how to fix it.
  • Gas analysis — the worst case of running the contract costs more than its activation amount covers.

The workflow rail at the top shows the result as Write ✓ compiles or the number of errors.

For the language itself — syntax, types, built-in functions — see the SmartC repository. In the editor, hovering over a built-in function shows its documentation.

  • Completion suggests keywords, built-in functions, your own functions and variables, and struct fields as you type.
  • Hover over a name to see what it is: a SmartC keyword, a built-in function (with the #include it needs, if any), or where your variable or function is declared.
  • Format document (Shift+Alt+F, on a Mac ⇧⌥F) tidies the indentation.

A new contract (Add File → SmartC contract) starts from a template with the structure most Signum contracts use: method codes as #defines, a loop over the incoming transactions with getNextTx(), and a switch that dispatches on the first number of the message.

Click Compile in the editor toolbar, or press Ctrl+Shift+C (on a Mac ⇧⌘C). The button is disabled while the contract has a compiler error.

The first compile creates the .asm file. A later compile overwrites it, so the Studio asks before replacing it. Open the .asm file to see the compiled contract: its code and data pages, memory layout, labels, machine code and code hash, plus the minimum fee and activation amount.

The linter knows the mistakes that cost money or lock up contracts. Among others it flags:

  • state changes or payments without checking who sent the transaction;
  • sendAmount or sendBalance without a balance check first;
  • loops without a bound;
  • a switch without default:, which silently accepts unknown methods;
  • a missing or different #pragma version, and a missing #pragma optimizationLevel;
  • a missing catch handler: after a fatal fault the contract would stay dead, with its balance locked in it;
  • deploy parameters that the top-level code overwrites before main runs.

Each warning comes with a hint, often with the exact code to add. Hover the marker to read it.

Every transaction to a contract has to carry at least its #program activationAmount; that pays for running the code. If the worst case costs more, the run stops halfway. The gas analysis works out the most expensive path through each handler and warns when the activation amount doesn’t cover it:

The worst case costs 0.32 SIGNA (handler withdraw), but activationAmount is 0.25 SIGNA.

The hint suggests a value (the worst case rounded up to 0.01 SIGNA). Loops are assumed to run a fixed number of times; a loop that runs longer costs more. For the cost model behind it, see Signum & AT concepts.

Add a Markdown file (Add File → Markdown (.md)) for notes, a README or instructions for others. The Markdown editor highlights the syntax; there is no preview.