Language Overview
Slvr is a production-ready smart contract language with:
- Linear type system (resource safety)
- Fuel metering (deterministic execution)
- Parallel execution (multi-core support)
- 60+ built-in functions
- IDE support (LSP, Debugger, Profiler)
- 100% Pact compatible
Basic Syntax
Functions
(defun hello (name)
"Greet someone"
(+ "Hello, " name "!")
)
(defun add (a b)
"Add two numbers"
(+ a b)
)Variables
(let ((x 10)
(y 20))
(+ x y)
)Conditionals
(if (> x 10)
"x is greater than 10"
"x is less than or equal to 10"
)Built-in Functions
String Functions
(+ "hello" " " "world")- Concatenate strings(length "hello")- Get string length(substring "hello" 0 3)- Extract substring(upcase "hello")- Convert to uppercase(downcase "HELLO")- Convert to lowercase
Math Functions
(+ 1 2 3)- Addition(- 10 3)- Subtraction(* 4 5)- Multiplication(/ 20 4)- Division(mod 10 3)- Modulo(pow 2 8)- Power
List Functions
(list 1 2 3)- Create list(length [1 2 3])- Get list length(first [1 2 3])- Get first element(rest [1 2 3])- Get rest of list(map + [1 2 3])- Map function over list
Cryptographic Functions
(blake3 "data")- Blake3 hash(sha512 "data")- SHA-512 hash(verify-signature sig pubkey msg)- Verify signature
Type System
Basic Types
int- Integerstring- Stringbool- Booleanlist- Listobject- Object/Map
Linear Types
Linear types prevent resource duplication:
(defun transfer (from to amount)
"Transfer tokens (linear type ensures no duplication)"
(let ((balance (get-balance from)))
(if (>= balance amount)
(do
(set-balance from (- balance amount))
(set-balance to (+ (get-balance to) amount))
true
)
false
)
)
)Fuel Metering
All operations have deterministic costs:
- Basic operation: 1 fuel
- String operation: 10 fuel
- Cryptographic operation: 1000 fuel
- Database operation: 100 fuel
Best Practices
- Always validate inputs
- Use linear types for resources
- Keep functions small and focused
- Document with docstrings
- Test thoroughly before deployment
- Monitor fuel usage
Ready to build?