Begining SC with Sophia


Hi everyone,
I’m trying to learn to create a SC with Sophia, but I’m stuck when trying to compile.
I’m learning with 3 different documentations :

  • /
  • /
  • /

But it seems that some docs are not up to date (about map() or events, for example), and I’m not sure about how much is implemented in the app

It also possible that my code is wrong, I don’t know, but can someone confirm that I can create events, and Map.lookup is a implemented function ?

Thank you.


Hey, I have forwarded your question to the dev team :slight_smile:




:+1: waiting for their answer :grin:


Hi @zorg

Events are not yet merged (they’re in a PR now) as you can see in protocol/contracts/ This repo is probably the best source of truth since the core developers that create Sophia, continuously update it.

There again, at protocol/contracts/ there is a list of all built-ins for maps. Map.lookup is one of them and it is working.

What relates to - there are a lot of different approaches for contract language design that had been tried out there. Most of those concepts had later on been refined in what currently Sophia is but some concepts had not yet made it in. So these are proto-contracts and some of them ado not compile at all. Please use them as a source of inspiration and not as a source of truth.


Hi @Dimitar.Ivanov
Thanks for your answer. It’s a little more clear for me.
Can you confirm me that uint are not yet implemented ? Some compilations didn’t worked for me with it ?

I tried to clean up my code, but now I don’t know if I’m wrong because of my lack of knowledge of Sophia of because I’m trying something not yet implemented.

Thanks to tell me if it’s better to create another topic instead of using this one, but can someone correct me this code ?

contract SomeToken =
    type balances = map(address, int)

    public function memberOf(owner : address) : int = 
        switch(Map.member(owner, balances))
            true => balances[owner]
            _    => 0

    public function lookupOf(owner : address) : int = 
        switch(Map.lookup(owner, balances))
            None 	=> 0
            Some(n) => n

I got a 403 : type_errors so I suppose it is Sophia grammar related…?