Functions & States
関数&状態

Looking at the bare bones of a smart contract we can see that contracts are merely collections of code (its functions) and data (its states) that correspond to a specific contract address on the blockchain.

スマートな契約の最低限を見ると、我々は、契約が単なるブロックチェーンの上に特定の契約住所に対応するコード(その関数)とデータ(その状態)の集まりだけであることを見ることができます。

For example, the line uint256 counter; sets the variable counter of type uint256 (unsigned integer of 256 bits). It can now be thought of as a single slot in a database that can be pulled by calling the function of the code that manages the database. We can even set a value for the variable counter while also setting the type as uint256.

例えば、一線 - uint256カウンター行; タイプ  uint256 (256ビットの無署名の整数)の変数カウンターを設定します。 それは今、データベースを管理するコードの機能を呼び出すことによって、引っ張ることができるデータベースで一つのスロットと考えることができます。 我々は、同じく変数カウンタータイプのために値をセットしさえすることができます。一方で uint256 としてそのタイプも設定します。

uint256 counter = 5;

 

State variables are typically outside of functions, making them global variables, and usually are the first few lines in our contract. We’ve now managed to set our variable counter as an uint256 and a value of 5. If we want to call a function to increase the value of counter by 1, we’re going to create a function (we’ll call it “add”) and tell it to add 1 to counter.

状態変数は、それらをグローバル変数にして、典型的に関数の外にあります。そして通常我々の契約書の中の最初の少数の行です。 我々は今、我々の変数を uint256 と5の値として設定するよう何とかうまくやりました。 もし我々が 1だけ値を増やすために関数をを呼び出すことを望むなら、我々は関数(我々はそれを「追加」と呼ぶでしょう)を作成して、それにカウンターに1を加えるように告げます。

function add() public {
  counter++;
}

After calling the function “add()”,counter will have a value of 6.
関数「add() 」を呼び出した後で、 カウンターは6の値を持つでしょう。

=====================================================================

人気ブログランキングへ人気ブログランキングへ=====================================================================