private function
 sieve( [] ) = []
 sieve(h: :t) = h: :sieve(List.filter((x) => x mod h != 0, t))

function primes_up_to(n : int) : list(int) =
 sieve([2..n])

SOPHIA

Our goal is to provide smart contracts capable of executing code while maintaining all of the following features:

  • Contract execution is safe
  • Contract execution is efficient and scales
  • Contract execution is cheap
Start coding now with REPL

private function
 sieve( [] ) = []
 sieve(h: :t) = h: :sieve(List.filter((x) => x mod h != 0, t))

function primes_up_to(n : int) : list(int) =
 sieve([2..n])

WHAT'S SOPHIA?

Sophia is a functional Smart Contract language in the ML family. It is strongly typed and has a restricted mutable state.

It was designed to utilize the full potential of the æternity protocol. It manages arbitrary-sized integers, doesn’t allow arithmetic overflows as well as any re-entrant remote calls. Additionally, some blockchain-specific primitives, constructions, and types are also present.

With Sophia, you can easily work with Oracles, the Naming System, Contract Factory, and many more features that interact with the æternity blockchain.

To learn more about its potential, jump
to the full reference.

BASICS

Remarkable capabilities like remote contract calling, contract cloning and contract creation make countless use cases possible. Get a deeper understanding of its main structure here.

Interaction
Events

Sophia contracts log structured messages to an event log in the resulting blockchain transaction. The event log is quite similar to Events in Solidity. Events are further discussed in the protocol.

Oracles &
Naming System

No need for external tools or setups. Create and query Oracles directly from your smart contracts. Use chain names also directly from your Sophia code to identify, claim, transfer (see full specs here).

Smart
Contracts

Sophia is customized for smart contracts, which can be published to a blockchain (the æternity blockchain). Thus some features of conventional languages, such as floating point arithmetic, are not present in Sophia, and some blockchain specific primitives, constructions and types have been added.

A Type Safe High-level Virtual Machine

Sophia: Avoiding Smart Contract Pitfalls

Aeternity Sophia 101: Your first token contract

Learn Building Sophia Contracts: Types & Functions

Contract Cloning and Child Contracts

Start coding your next Sophia smart contract right now with our æternity Studio online, no extra tools needed.

Sophia examples

LEAD TO SOPHIA
REFERENCES

Find some of our examples that will show you from a practical point of view how to interact with the æternity blockchain. You will find examples of Oracles, Non Fungible Tokens (not official standard), SmartShop and some simple training examples.

Take me to examples

contract IntHolder =
  type state = int
  entrypoint init(x) = x
  entrypoint get() = state

main contract IntHolderFactory =
  
stateful entrypoint new(x : int) : IntHolder =
    let ih = Chain.create(x) : IntHolder
    ih

Copy

Contract Factory

Payable contract
& Entrypoints

// A payable contract and entrypoint
payable contract PayableContract =
  
payable stateful entrypoint transfer_item(to:address) =
    
Chain.spend (to, 42)
  
payable stateful entrypoint buy(to : address) =
    if(Call.value > 42)
      transfer_item(to)
    else
      abort("Value too low")

Copy