SourceLess · AsgardAsgard · chain 1313

Part III · Building on the chain · Chapter 4 of 15

Deploying a smart contract

A contract from source to an address on a chain, in the order the commands have to run.

15,570 bytes 2,287 words newest date 2026-11-23

Verify: the published bytes are in the raw file DEPLOYING_CONTRACTS.md, whose SHA-256 is in SHA256SUMS.
1baa4b2eae420bd987e7ea6cb65a30501934e768f0a6b7488ca52786cd30f2bd

Created by Alex M Stratulat and the SourceLess team.

End to end: write an AresLang contract, get an account that is allowed to deploy one, deploy it, call it, and read what changed. Every command here was run against a live local chain, and every behaviour asserted is pinned by tests/integration/contract-lifecycle.integration.test.ts.

If something here stops being true, that test fails.


Before you start#

You need a running chain. The shortest path is the local network:

npm run build
node scripts/polaris.mjs up --supervise
node scripts/polaris.mjs seed

seed matters and is not optional: it creates four wallets, funds them, and proves domains for three of them. A bare chain has nobody who can spend — see §2 — so without it your first transaction is refused and the chain sits at height 0.

Polaris chooses ephemeral ports. Read the real one rather than guessing:

node -pe "JSON.parse(require('fs').readFileSync('.sourceless/polaris/polaris.json','utf8')).nodes[0].rpcUrl"

Everything below uses $RPC for that value.


1. Write the contract#

Save this as tally.ares:

contract Tally {
  state count: uint = 0;
  state owner: address = caller;
  event Bumped(by: address, total: uint);

  fn bump(step: uint) -> uint {
    require(step > 0, "step must be positive");
    count = count + step;
    emit Bumped(caller, count);
    return count;
  }

  view fn total() -> uint { return count; }
}

Four things to notice:

  • state fields are the contract's storage. Their initialisers run once, at deployment, so owner is the deployer.
  • caller is the authenticated caller, not a string somebody claimed. It used to be unauthenticated, which made every require(caller == owner) decorative; a call now carries a signature over the exact call and the ledger checks it before executing.
  • view fn reads and cannot write.
  • require reverts. A revert is the contract working.

The language reference is AresLang and the VM; ready-made contracts are in the template catalogue, each shipping with the adversarial test that proves its guard is load-bearing.


2. Get an account that may deploy#

A contract call is a spend of network work. It consumes gas, it is sealed into a block every node replays, and post-mining mints STR against it. So the same rule as spending applies: the deployer must hold a proved STR.domain. Without one:

zk13str_… has no proved STR.domain; SourceLess requires one to deploy or call a contract

Make a wallet:

export SOURCELESS_KEY_PASSPHRASE='a passphrase you will not lose'
strblk wallet create --file ./my.json --node $RPC

It will tell you it holds no domain and can do nothing with value yet. Get it funded — from a seeded wallet, an exchange, anybody — with at least 1,000 STR plus what you intend to spend.

Then spend once:

strblk wallet send <any-address> 1 --minor --file ./my.json --node $RPC

That single transaction is enough. The chain names the account in the block that carries it, takes the 1,000 STR lock and mints the wNFT — this is Nafnfestr, described in How it works §2. Confirm:

strblk wallet show --file ./my.json --node $RPC
  STR.domain                 STR.uj7la4jy5urn6vdxekrdeeogmeycofgwar66donind2daz3dziwq
                             named by the chain on its first spend, not chosen by anybody.
  domain state               proved — wNFT 55228d18…, 1000 STR locked

If you would rather choose a readable name, strblk wallet register STR.yourname books and proves one instead.


3. Deploy it#

strblk wallet deploy ./tally.ares --file ./my.json --node $RPC
Tally is queued for deployment

  address                    zk13str_6e1329f99efc312d7a0081df386107cd55e56726_15c2
  deployer                   zk13str_2e9dec10e59d7f18fdd8ca3d037ca0af328fd8ac_4ad9
  salt                       (none)

Two things catch people out here. Both are deliberate design choices, and each has a consequence that is not:

You have the address already. It is derived from name + bytecode + deployer + salt - deriveContractAddress in contracts/registry.ts - not assigned by a producer, so you can put it in a config file before the block exists. Pass --salt TEXT to deploy the same contract twice from one account.

The bytecode is in that preimage, and it is the half people drop. This page said deployer + name + salt until 2026-09-18, which is the same address for two different programs and makes the compiler version look like a detail. It is not: a deploy record carries SOURCE, so the address depends on the bytecode THIS node builds from it. Two nodes on different AresLang versions can derive two different addresses from one record, which is a state-root fork a few blocks later. That is why a deploy naming a compiler this node does not run is refused by name, and why src/core/logretta.ts treats the compiler version as a consensus rule rather than a build detail.

Nothing has run. queued is the whole truth. The constructor executes when a block carries the record, and — because a record does not gossip — that is when the node you submitted to next seals, which can be a full producer roll away.

And if that node never seals, the record waits for ever. There is no timeout and no refusal: it stays queued, the account's contractNonce has already moved, and refusedRecords stays empty. Measured on 2026-09-18 against a three-node mesh where one seat had produced 0 of the last 61 blocks - a deploy sent to it was still not in state twenty minutes later. Contract records are direct rather than flooded on purpose, because a relay would have to compile the bytecode to authenticate the record, so no other node can pick it up for you. Submit to a node you have watched seal, and if a deploy has not landed within a producer roll, resubmit to a different one.

Since 2026-11-23 a node that cannot seal says so: it refuses the deploy or call, naming why (no seat at the next height, or no key it may seal with), before it compiles anything, and a node that can seal answers with a reach saying the record is queued there and passed to no peer. A node that can seal and is simply slow to lead a block still answers queued, so the advice above stands.

Confirm it landed:

curl -s $RPC -X POST -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"contractStorage","params":{"address":"<address>"}}'
{"result":{"address":"<address>","slots":2,"after":null,"limit":512,"maxBytes":1048576,
  "returned":2,"clamped":{"rows":false,"bytes":false,"withheld":0},"more":false,"next":null,
  "entries":[{"key":"count","value":"0"},{"key":"owner","value":"zk13str_2e9dec…"}]}}

Before the block, that call answers unknown contract address — not an empty page. "Not deployed yet" and "deployed and holding nothing" are different facts and this surface keeps them apart.

The answer is one page, in key byte order, never the whole map: at most 512 slots and 1 MiB of rows. clamped says which cap shortened it, more says whether slots remain, and next is the key to pass back as after for the following page. A slot whose value alone is over the byte budget comes back with valueWithheld and its size instead of the value. contractEvents pages the same way, by event sequence, at most 256 events a page, and also reports how many events this node retained and dropped. An unpaged read of either used to let one cheap call make every request build a body of hundreds of megabytes.


4. Ask what a call would do#

simulateCall runs against current state and commits nothing: no nonce, no storage leaf, no event, no state root.

curl -s $RPC -X POST -H 'content-type: application/json' -d '{
  "jsonrpc":"2.0","id":1,"method":"simulateCall",
  "params":{"address":"<address>","functionName":"bump","caller":"<your-address>","args":["7"]}
}'
{"result":{"success":true,"reverted":false,"returnValue":"7","gasUsed":464,"events":[]}}

This is the only honest way to ask "what will this return" before a block has executed it — and it is not a promise. State can move before your queued call is sealed, so a simulation that succeeds can still revert on chain.


5. Call it#

strblk wallet call <address> bump --arg 7 --file ./my.json --node $RPC

Again you get a receipt, not a result. What a call does is decided when the block is sealed and every node executes the same record.

Once it seals, read the state and the events:

curl -s $RPC -X POST -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"contractStorage","params":{"address":"<address>"}}'
curl -s $RPC -X POST -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"contractEvents","params":{"address":"<address>"}}'
# the next page, when the last answer said "more": true
curl -s $RPC -X POST -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"contractEvents","params":{"address":"<address>","after":<next>}}'

6. Doing it from your own code#

If you are building a client rather than typing commands, you sign the authorization yourself. This is the whole flow, and it is what the integration test does:

import { compileAresContract } from './runtime/areslang.js';
import { signDeployAuthorization, signCallAuthorization } from './src/core/contract-state.js';

// 1. What chain are you signing for? A signature binds to one genesis and no other.
const genesis = await rpc('genesis', {});

// 2. Compile LOCALLY. The signature covers the BYTECODE, not the source text: signing source
//    would let a node that compiled it differently deploy something you never authorised.
const compiled = compileAresContract({ source: SOURCE });

// 3. The nonce your next authorization must sign over. It counts settled AND queued records,
//    because the chain is the only thing that can see both halves.
const { nonce } = await rpc('contractNonce', { caller: me.address });

// 4. Deploy.
const deployed = await rpc('deployContract', {
  source: { name: compiled.name, source: SOURCE },
  deployer: me.address,
  authorization: signDeployAuthorization(me, {
    name: compiled.name,
    bytecodeHex: compiled.bytecodeHex,
    nonce: BigInt(nonce),
    chain: genesis.chainBinding,
  }),
});

// 5. Call. NOTE THE FIELD NAME — see the warning below.
await rpc('callContract', {
  address: deployed.address, functionName: 'bump', caller: me.address, args: ['7'],
  authorization: signCallAuthorization(me, {
    contractAddress: deployed.address,   // NOT `address`
    functionName: 'bump',
    args: [7n],
    nonce: BigInt((await rpc('contractNonce', { caller: me.address })).nonce),
    chain: genesis.chainBinding,
  }),
});

The mistake that costs the most time#

signCallAuthorization takes contractAddress. Write address instead — the obvious guess, and the name the RPC itself uses one line above — and JavaScript will not stop you. The payload is then signed over undefined and the signature verifies against nothing.

Until 2026-11-11 that record was refused at the seal rather than at submission: you were told queued, and the call simply never happened. The door now checks a call's signature before it queues anything, so the same mistake is refused at once with caller authorization: signature does not verify over this call. If you see that sentence, check this first.

A deploy's signature covers the bytecode, so the door can verify it only when it compiled the source itself, which the RPC door does. A deploy relayed from a peer is checked for the key, the deployer and the nonce at the door, and for the signature at the seal.

Bigints travel as decimal strings in both directions, so use a replacer:

JSON.stringify(payload, (_k, v) => (typeof v === 'bigint' ? v.toString() : v))

7. When a call does not land#

In order of likelihood:

  1. The block has not been sealed yet. A record is sealed by the node you sent it to, when that node's slot comes round. A moving height is not proof that it was: an idle chain seals an empty heartbeat block about once a minute (heartbeatDue src/node/hestia.ts:4690), so check the block your record should be in, not only the height. Until 2026-10-29 this said a node "does not seal empty blocks", which stopped being true on 2026-10-11.
  2. The authorization signed the wrong bytes. contractAddress (§6), or a stale nonce, or a missing chain — omitting the chain signs for no chain, and no chain accepts it.
  3. The caller holds no proved domain (§2).
  4. The contract reverted. Use simulateCall with the same arguments; a revert there is a revert on chain.

Ask the node why. refusedRecords answers with the kind, the record it was about, and the reason:

curl -s $RPC -X POST -H 'content-type: application/json'   -d '{"jsonrpc":"2.0","id":1,"method":"refusedRecords","params":{}}'
{"refused":[{"kind":"contract",
             "reference":"zk13str_0eac06821d16843bc9535104c4628b4558063c53_cdfd",
             "reason":"caller authorization: signature does not verify over this call"}]}

This answered [] for every record on every running node until 2026-09-18, and the reason is worth knowing because it is the shape of bug this surface exists to prevent. The producer drains each refusal buffer on every seal so it can alert on each refusal exactly once (HestiaNode.reportRefusedRecords calls takeRefused*, which splices them empty), and this method read those same buffers. So it was permanently empty on anything that had produced a block, while the reason went to the node's alert sink — stderr, lost on a detached process. Refusals are now journalled separately from the buffers that feed alerting, and the journal is never drained. If you are on an older build, [] here means nothing either way.


8. What is not here#

  • There is no strblk compile. You cannot see bytecode, an ABI, or a syntax error without deploying. The compiler is reachable from code (compileAresContract), not from the CLI.
  • There is no wallet read or wallet view. After calling, you leave the CLI for XPlorer or raw JSON-RPC to see what happened. simulateCall is the closest thing to a read verb.
  • Gas is bounded per record and per block, and nothing lets you choose a gas price, because there is no fee market — see How it works §4.

Next#