【CryptoZombies】lesson1 Chapter 7: Function Declarations

A function declaration in solidity looks like the following:

function eatHamburgers(string memory _name, uint _amount) public {

}

This is a function named eatHamburgers that takes 2 parameters: a string and a uint. For now the body of the function is empty. Note that we're specifying the function visibility as public. We're also providing instructions about where the _name variable should be stored- in memory. This is required for all reference types such as arrays, structs, mappings, and strings.

eatHamburgersのメソッドに引数が2つ(a string and a uint)ある認識。また、関数パラメーター変数名はアンダースコア(_)をつけるのが通例(必須ではない)。

test

In our app, we're going to need to be able to create some zombies. Let's create a function for that.

1.Create a public function named createZombie. It should take two parameters: _name (a string), and _dna (a uint). Don't forget to pass the first argument by value by using the memory keyword
Leave the body empty for now — we'll fill it in later.

pragma solidity >=0.5.0 <0.6.0;

contract ZombieFactory {

   uint dnaDigits = 16;
   uint dnaModulus = 10 ** dnaDigits;

   struct Zombie {
       string name;
       uint dna;
   }

   Zombie[] public zombies;

   // start here
   function createZombie(string memory _name, uint _dna) public {

   }

}

publicを忘れないようにする


この記事が気に入ったらサポートをしてみませんか?