Begining SC with Sophia


#1

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 :

  • /dev.aepps.com/aepp-sdk-docs/Sophia.html
  • /github.com/aeternity/protocol/blob/master/contracts/sophia.md
  • /github.com/aeternity/epoch/tree/master/apps/aesophia/test/contracts

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 https://contracts.aepps.com/

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.


#2

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


#3

Sophia是用来写合约的,不是用来创建状态通道的,你应该用JsSDK或者pySdk来创建


#4

:+1: waiting for their answer :grin:


#5

Hi @zorg

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

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

What relates to github.com/aeternity/epoch/tree/master/apps/aesophia/test/contracts - 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.


#6

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…?