0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Solidity]変数の型について

Last updated at Posted at 2022-05-24

Solidity.png

いつもはflutterを書いているのですが、ブロックチェーンに興味をもち勉強を始めました。
アウトプットのために書こうと思います。
自分用のメモにも使います。

数字関連

  //正の数と負の数の両方使用できる。
  int a = -5;
  //正の数しか使えない。
  uint b = 3;

注意点

・小数は使えない  例) 0.5ETH = 0.5 * 10^18 wei で表せる!

文字列関連

    //String型
    string d = 'Hello world';
    //文字列の長さに制限がある(下の場合は、32)
    bytes32 e = 'EHT';

メモ

・byte32は、EHTBCTなど決まった長さに使用することが多い

アドレス型

 

   //ウォレットのアドレスなどで使用する。
   address f = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;

bool型

        //true or falseが使用可能
    bool c = false;

簡単関数例

pragma solidity >= 0.4.0 < 0.8.9;

contract MyContract{
    int a = -5;
    uint b = 3;
    bool c = false;
    string d = 'Hello world';
    bytes32 e = 'EHT';
    address f = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;

      
    function add (uint x, uint y) public pure returns(uint) {
        uint result;
        result = x + y;
        return result;
    }

  
    function addByB(uint x) public view returns(uint result) {
        result = x + b;
    }

    function changeB(uint x) public returns(uint) {
        b = x;
        return b;
    }
}

結果

スクリーンショット 2022-05-24 14.33.39.png

注意点

solidyは、uintの方が使われる 
→ マイナスがあまりないから。

最後に

まずは基本からやっていこうと思っています。
修正点があれば、コメントください!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?