Skip to main content

Tutorial: Your First Lyquid

This tutorial shows you how to build your first Lyquid by reimplementing a Solidity contract (GreeterStorage) using Rust. This contract is an interesting combination of Solidity's previous (Greeter) and current (SimpleStorage) example for the first contract. You'll quickly see how Lyquid matches Solidity's simplicity while enabling much richer logic through its unified state model and powerful off-chain capabilities.

Original Solidity Reference (hello.sol):

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

import "@openzeppelin/contracts/utils/Strings.sol";

contract GreeterStorage {
using Strings for uint256;

string public greeting;
uint256 public greetCount;

constructor(string memory _greeting) {
greeting = _greeting;
}

function setGreeting(string calldata _greeting) external {
greeting = _greeting;
}

function greet() external {
greetCount += 1;
}

function getGreetingMessage() external view returns (string memory) {
return string(
abi.encodePacked(
greeting,
"I've greeted",
greetCount.toString(),
" times to on-chain users"
)
);
}
}