【Hello World & First Contract】

不免俗的來 Hello World 一下吧!

pragma solidity ^0.8.11;
contract HelloWorld {
    string public helloworld = "Hello World!";
}

如何理解 Solidity 的運作模式:可以把 set() 視做 input,把 get() 視做 output。當然這邊的 set()get() 是我們自己定義的函式,想要取其他的名子也可以!

pragma solidity ^0.8.11;

contract FirstContract {
    uint public myVar;

    function get() public view returns (uint) {
        return myVar;
    }

    function set(uint x) public {
        myVar = x;
    }
}

這邊先偷跑一下之後的內容,在 get() 這個函數裡面:

  • public 代表這個函數的可視性(Visibility),意思就是說我們可以在 Remix interface 跟它互動。

  • view 的意思則為這個函數是唯讀(read-only)的。

  • returns 就像我們已經認識的其他程式語言一樣,這個函數會回傳一個型別為 uint 的值

Last updated

Was this helpful?