Cryptozombie Part 1

Cryptozombie Part 1_第1张图片
This is a summary of learning solidity by building a Dapp game

Edit page:

Cryptozombie Part 1_第2张图片

Learning summary:

■  A contract is the fundamental building block of Ethereum applications — all variables and functions belong to a contract, and this will be the starting point of all your projects.

State variables are permanently stored in contract storage. This means they're written to the Ethereum blockchain. Think of them like writing to a DB.

The uint data type is an unsigned integer, meaning its value must be non-negative. There's also an int data type for signed integers.

■ Structs allow you to create more complicated data types that have multiple properties.

■ There are two types of arrays in Solidity: fixed arrays and dynamic arrays:

e.g uint[2] fixedArray;

      string[5] stringArray;

      uint[ ] dynamicArray; // a dynamic Array - has no        fixed size, can keep growing

      array.push() adds something to the end of the          array

■ A function declaration in solidity looks like the following:

  function eatHamburgers(string _name, uint _amount) {

}

■ In Solidity, functions are public by default. This means anyone (or any other contract) can call your contract's function and execute its code. However it's a good practice to mark your functions as private by default, and then only make public the functions you want to expose to the world.

■ Return Values

To return a value from a function, the declaration looks like this:

Cryptozombie Part 1_第3张图片

■ Ethereum has the hash function keccak256 built in, which is a version of SHA3. A hash function basically maps an input string into a random 256-bit hexidecimal number. A slight change in the string will cause a large change in the hash.

■ Events are a way for your contract to communicate that something happened on the blockchain to your app front-end, which can be 'listening' for certain events and take action when they happen.

once Solidity contract is completed, we need to write a javascript frontend that interacts with the contract. Ethereum has a Javascript library called Web3.js. In the later article, I'll go over in depth how to deploy a contract and set up Web3.js.

Cryptozombie Part 1_第4张图片

你可能感兴趣的:(Cryptozombie Part 1)