Guides
Examples
The examples/ directory contains runnable source programs. Start with small contracts and move to composite ABI/storage cases.
Suggested learning order#
Counter.jeth: state, checked arithmetic, and an external getter.Arith.jeth: integer operations and panic behavior.Control.jeth: branches and loops.Globals.jeth:msg,block, andtxdata.Events.jeth: event topics and data.Errors.jeth: revert strings and custom errors.Arrays.jeth: dynamic arrays.FixedArrays.jeth: fixed arrays.Structs.jeth: struct construction and storage.Nested.jeth: nested state shapes.Vault.jeth: a larger end-to-end contract.CloneFactory.jeth: CREATE and CREATE2 EIP-1167 clones with atomic initialization.
Small complete examples#
Owned counter#
class OwnedCounter {
owner: address;
count: Visible<u256>;
constructor(initialOwner: address) {
require(initialOwner != address(0n), "zero owner");
this.owner = initialOwner;
}
increment(): External<void> {
require(msg.sender == this.owner, "not owner");
this.count += 1n;
}
}Deploy with an owner constructor argument. increment() succeeds only from that address, and the generated count() getter returns the current value.
Typed token payout#
interface Token {
transfer(to: address, amount: u256): bool;
}
class TokenPayout {
owner: address;
constructor(initialOwner: address) {
this.owner = initialOwner;
}
pay(
token: address,
recipient: address,
amount: u256,
): External<void> {
require(msg.sender == this.owner, "not owner");
const transferred: bool = Token(token).transfer(recipient, amount);
require(transferred, "transfer failed");
}
}The interface supplies the selector and ABI schema. The external call can reenter, so the production version must account for any state it adds before making the call.
Compile an example#
npm run jethc -- examples/Vault.jeth --abi --layout
npm run jethc -- examples/Vault.jeth -o build/vaultExample quality policy#
Shipping examples should be:
- small enough to explain one concept clearly;
- compiled in CI;
- paired with runtime assertions when behavior matters;
- explicit about security assumptions;
- free of audit-only names such as
_reproor_advin the public learning path; - linked from a guide page that explains expected output.
The repository also contains adversarial and generated examples used for compiler coverage. They are valuable engineering fixtures but are not tutorials.
Repository examples still planned#
- ERC-20-like token with branded units and custom errors;
- access-controlled vault using checks-effects-interactions;
- typed interface call and
try/catch; - internal and external library linking;
- upgradeable proxy deployment and safe upgrade walkthrough;
- diamond deployment and selector management;
- calldata slicing plus ABI decoding;
- signed-message recovery with replay protection;
- fixed-point math with explicit rounding once the audited math package exists.