Atlas

Write your first contract

A Counter in Solidity and Omegyu, from one storage word to a constructor, a getter and a transaction that changes the count.

Start with a contract whose entire state you can predict. Deploy it with 10, call increment(), and the next count() must return 11. Both versions below expose those two Solidity ABI functions. The caller does not need to know which language produced the bytecode.

Start from the Solidity contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.33;

contract Counter {
    uint256 public count;

    constructor(uint256 start) {
        count = start;
    }

    function increment() external {
        unchecked { count += 1; }
    }
}

Solidity does three jobs with uint256 public count: it chooses a representation, reserves storage, and generates a getter. The unchecked block is intentional: this counter wraps from the largest uint256 to zero. Solidity's default checked + would instead revert there.

Write the Omegyu contract

Here is the whole file. You can open this listing in the playground and edit it; there are no imports from a starter project.

Counter.omg
let C = std:EVM/Contract
let State = { count : Word 256 }
let Args = { start : Word 256 }
let step = Word/fromNatural 256 1
let contract =
      (C.storage State).bind
        (\state ->
           let write = C.monad @State C.Mode.Write
           let methods =
                 C.methods
                   { count = C.define (C.reading { Args = {}, Result = Word 256 }) (\_ -> state.count.read)
                   , increment =
                       C.define (C.writing { Args = {}, Result = {} })
                         (\_ -> do write {
                           previous <- state.count.read;
                           state.count.write (Word/add previous step)
                         })
                   }
           in  C.compose
                 { State, Args = C.solidityCodec Args }
                 { constructor = \a -> state.count.write a.start, facets = [ methods.facet ] })
in  { contract }
Your result
Complete example · with imports

EVM interfaceruntime 153 bytes, deployment 204 bytes

0x06661abd  count()
0xd09de08a  increment()
0x4f4d4701bf3133a4  count (view)
0x4f4d4701cdcc9267  increment (nonpayable)
  1. Name the state and its starting value. Word 256 is the bounded unsigned word that the ABI calls uint256. State is what survives a transaction. Args is a separate record: start exists during construction, but there is no start storage slot.

  2. Give the methods access to storage. (C.storage State).bind gives the body a state.count accessor, not the current integer. Reading and writing that word are actions. C.reading permits the read in the getter but not the write in increment.

  3. Sequence the update. previous <- state.count.read runs the read before the next line. Word/add wraps at 256 bits, matching the Solidity unchecked block. The last action writes the sum. Its result is empty: look at a receipt to learn whether the write succeeded, then call the getter for the new value.

  4. Choose what callers see. C.methods uses the field labels for the method names. {} means no arguments in both declarations and no returned values in increment. C.solidityCodec Args selects the Solidity ABI for the constructor. C.compose joins the constructor and method group; in { contract } exports what the compiler builds. The default methods also have native routes. A Solidity client uses only the four-byte ABI selectors.

Deploy, call, then change the code

Open the Omegyu listing in the playground. Choose Build for the EVM, then switch from Editor to VM lab in the workspace bar. The compiler answer describes the build; the lab runs it. Use Deploy instance for each build and the address rows under Deployed code to return to the first instance. A build produces creation code; it does not create an account until you deploy it.

ActionWhat to look for
Deploy with start set to 10. Keep the address; call it A.Creation runs the constructor once. Slot 0 now holds 10 (0xa). The deployment receipt reports gas used.
Read count() on A.The result decodes to 10. A simulated read does not commit any state.
Send increment() to A, then read again.The transaction returns no count. Slot 0 changes from 10 to 11 and the read returns 11. Its gas is the cost of this transaction, not of compiling the program.
Edit Word/fromNatural 256 1 to Word/fromNatural 256 2. Build again and deploy with 10. Call this address B.B starts at 10, not at A's current count. Editing a source file cannot replace the code at A.
Send increment() to B. Read B, then A.B returns 12; A still returns 11. Same function selector, different deployed code and separate storage.

On address A, switch Solidity ABI to Native and read count() again. The call now uses the eight-byte native header shown above, not the Solidity selector; it still reads 11 from the same address. Switching the interface does not deploy another instance.

Want a checked overflow policy or a getter with a different public name? Continue with the larger Counter. For how a Solidity contract calls an Omegyu address, see the Solidity caller.