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】(tips)引数の指定方法

Posted at

今回は引数の指定方法に関して、メモします。
2つの数字を返す関数numと、num関数を呼び出すexNum関数を定義します。
exNum関数の中でnum関数を呼び出す際に、引数を指定する場合は下記のようになります。
exNum関数に(1,2)の順番で引数を渡し実行すると、(1,2)の順番で値を返します。

pragma solidity ^0.8.17;

contract Sample{

    function num(uint _a, uint _b)internal pure returns(uint, uint){
        return (_a, _b);
    }
 
    function exNum(uint _s, uint _t)public pure returns(uint, uint){
        return num({_a:_s, _b:_t});
    }
}

ここで下記のようにexNum関数内で呼び出しているnum内を変更し、
exNum関数に(1,2)の順番で引数を渡し実行すると、(2,1)の順番で値を返します。
このようにnum({_b:_s, _a:_t})で渡す値を指定できます。

pragma solidity ^0.8.17;

contract Sample{

    function num(uint _a, uint _b)internal pure returns(uint, uint){
        return (_a, _b);
    }
 
    function exNum(uint _s, uint _t)public pure returns(uint, uint){
        return num({_b:_s, _a:_t});
    }
}
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?