Solidity Language Basics

Solidity

If you are familiar with C based language, it will be a breeze.

If

if (<boolean expr>) {
    cond
} else if (...) {
} else {
}

loops

for (uint i = 0; i < 10; ++i) {
    ...
}

contracts

Basic building block

contract Name {
    ...
    uint foo = 5;
    constructor() {
        // I am called once at contract deploy
    }

    function name() scope returns(type) {
        ...
    }
}

Simple Types

uint = 256 bit number uint8, uint16, uint32, ...

strings suck

arrays

  • there are dynamic and static
contract Foo {
    uint[] foo; // Hello I am dynamic
    function foofoo() public view {
        uint[] fooo = new uint[](10); // I am fixed array
    }
}

maps

  • these are much different. You cannot iterate.
contract Foo {
    mapping(uint => address[]) mymap;
}

structs

  • Just like c
struct Foo {
    uint a;
    uint16 b;
    uint8 c;
}
mapping(uint => Foo) mymap;
Foo[] myarr;















The language is simple, the concepts are hard

  • You can learn everything you ever wanted from Solidity. So it seems a bit redundant to just recreate the same tutorial. Lets make something instead.
  • As we build we will learn















Questions?