Solidity備忘録⑤(2021年5月21日)

現在、Remixを使ってSolidityをコンパイルを行おうと思っています。

SPDXについての警告文が出ましたが、今回は不要なため、そのまま進むこととします。

さて、Remixで次の処理に進んでいきます。
左側の真ん中の「Deploy & Run Transaction」です。

スクリーンショット (125)

オレンジ色の「Deploy」を押してみます。すると

スクリーンショット (126)

Deployed Contractのところに新しく追加されました。

今まで「Currently you have no contract instances to interact with」(現在作用するコントラクトのインスタンスはありません)となっていた部分です。

さらにこのコントラクトを押してみると、こんな感じです。

スクリーンショット (127)

「Low level interactions」
⇒低いレベルでの交流
 ⇒ここでデータのやり取りなどができるのかも。。

ちなみに「Transact」を押すと
「Both ”receive” and ”fallback” functions are not defined」と出ました。

確かに

①Receive function
②fallback function

のどちらも定義しておりません。

ちなみに「fallback」は「最後のよりどころ」といった意味のようですが、どういう意味だろう。。

では、この2つを勉強していきます。

Receive functionから

スクリーンショット (129)

Receive Ether Function

⇒Etherを受け取るfunction

A contract can have at most one receive function, declared using receive() external payable { ... } (without the function keyword). 

⇒Contractは最大一つreceive functionを持つことができます。
 functionというキーワードはいりません。

This function cannot have arguments, cannot return anything and must have external visibility and payable state mutability. 

このfunctionは引数を持たず、何も返さず、多くの場合、外部から見ることができ、「payable」stateが可変的である。

It is executed on a call to the contract with empty calldata. This is the function that is executed on plain Ether transfers (e.g. via .send() or .transfer()). 

これは空のcalldataとともに実行される。これは単純なEtherの送付時に実行される。

If no such function exists, but a payable fallback function exists, the fallback function will be called on a plain Ether transfer. 

もし、receive functionがなくても、「payable fallback function」があれば、そのfunctionは単純なEtherの送付時に呼び出される

If neither a receive Ether nor a payable fallback function is present, the contract cannot receive Ether through regular transactions and throws an exception.

もし、どちらもなければ、コントラクトはEtherを受け取れないし、Exceptionも投げることができない。

今回はEtherのやり取りをしないのでここは飛ばしていこうと思います。

続きは次回にします。

サポートをしていただけたらすごく嬉しいです😄 いただけたサポートを励みに、これからもコツコツ頑張っていきます😊