Solidity


Basic Structure for NFT Market App

**Front-end Application: ** receive token urls point to metadata

NFT Market(smart contract): generate token id based on token uri and owner and the token

**Pinata: **Stores metadata for tokens

Add Ethereum to global window type

**Access it in browser: **

Solidity Version

Exact version 0.8.7

Any version of 0.8.7 and above is ok about the contract

version range

Types in Solidity

  • bool(boolean)

  • uinit

  • int

  • address

  • bytes

solidity initialize int value into 0

Visibility

default visibility is internal

for each public variable would a getterfunction would be automatically generated

View and Pure

function with **view and pure ** does not cost gas when it is executed

  • view: function could not modify block chain state, but could read
  • pure: disallow both read and write

**Exception: ** calling view and pure functions inside a function that costs gas would lead to extra gas:

struct

Data Location

Data location could only be given for array, struct, mapping types(string is array)

  • Memory: variable erased after used by functions, stored in memory
  • Storage: would be permanently stored in block-chain
  • calldata: immutable, could only be used for function parameters, same as Memory in lifespan

default type of variable is Storage

Data location could only be given to the array(string is array), strcut or mapping types

in Solidity, uint = uint256

in Solidity, size of array could be fixed or not fixed

Require in Solidity

in Solidity Require works as if....throw:

Virtual and Override

Using address(0) to judge empty address

In ERC721, _beforeTokenTransfer would be invoked in: _transfer, _burn and _transfer

Using ERC721.balanceOf(address) to get the number of token in an address


A u t h o r: Joe
P o l i c y: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Joe !
Leave Your Comment Here
  TOC