五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

(32 小時最全課程)區(qū)塊鏈,智能合約 & 全棧 Web3 開發(fā)

2023-08-09 23:07 作者:Pray4lov3  | 我要投稿

# Full BlockChain Solidity Learning


## Chapter #1


### Calculate Transaction Fee


Transaction Fee = ( Block Base Fee Per Gas + MaxPriorityFee Per Gas ) \* Gas Used


- Base Fee: The minimum "gas price" to send your transaction


- 1 Eth = 1000000000 GWei = 1000000000000000000 Wei


### Consensus


Consensus is the mechanism used to agree on the state of a blockchain.


#### 1. Chain Selection Algorithm


#### 2. Sybil Resistance Mechanism


- Like PoW(Proof of Work) and PoS(Proof of Stake)


## Chapter #2


### First Contract in Remix


```sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;


// This is a smart contract

contract SimpleStorage {

// The basic types: boolean | unit | int | address | bytes

// unit: POSITIVE number only


bool hasFavoriteNumber = true;

uint favoriteNumber = 123;

string favoriteNumberInText = 'five';

bytes favoriteBytes = 'cat';

}

```


> Default Value

> `uint favoriteNumber; // 0`


### Function


```sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;


// Contract: 0xd9145CCE52D386f254917e481eB44e9943F39138

contract SimpleStorage {

uint256 favoriteNumber;


function store(uint256 _favoriteNumber) public {

favoriteNumber = _favoriteNumber;

}


// getter function of favoriteNumber

function retrieve() public view returns(uint256) {

return favoriteNumber;

}

}

```


> **Tips:**

>

> - Smart Contracts have addresses just like our wallet accounts do.

> - Any time you change something on-chain, including making a new contract, it happens in a transaction.(部署合約其實就是在發(fā)送一個交易;我們在區(qū)塊鏈上做任何事情,修改任何狀態(tài),其實就是在發(fā)送一個交易)

> - `view, pure`: 標(biāo)記上后不會花費 gas,因為這意味著我們只會讀取這個合約的狀態(tài)(除非你在要花費 gas 的 store 函數(shù)中調(diào)用它)

> - `view and pure` functions disallow modification of state.(我們不可以在這個函數(shù)里修改任何狀態(tài))


#### Function Visibility Specifiers


- public: it creates `getter()` automatically.

- private: only visible in current contract.(此合約可見)

- external: only visible externally.(合約外部可見,合約外的賬戶可以調(diào)用這個函數(shù))

- internal(default visibility ): only visible internally.(合約內(nèi)部可見,這有這個合約或者繼承它的合約可以調(diào)取)


### Arrays and Structure


We want to store different people with different numbers here. So we are using `struct`.


```sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;


// Contract: 0xd9145CCE52D386f254917e481eB44e9943F39138

contract SimpleStorage {

uint256 public favoriteNumber;

// Instantiate a person

People public person = People({favoriteNumber: 12, name: 'Logic'});


struct People {

uint256 favoriteNumber;

string name;

}


function store(uint256 _favoriteNumber) public {

favoriteNumber = _favoriteNumber;

}


// getter function of favoriteNumber

function retrieve() public view returns(uint256) {

return favoriteNumber;

}


}

```


We are storing the structures as an array here


```sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;


// Contract: 0xd9145CCE52D386f254917e481eB44e9943F39138

contract SimpleStorage {

uint256 public favoriteNumber;


struct People {

uint256 favoriteNumber;

string name;

}


// 這里用people數(shù)組來存儲多個`struct`的實例`People`

People[] public people;


// Add `people` function

function addPerson(string memory _name, uint256 _favoriteNumber) public {

People memory newPerson = People({favoriteNumber: _favoriteNumber, name: _name});

// People memory newPerson = People(_favoriteNumber, _name);

people.push(newPerson);

}


function store(uint256 _favoriteNumber) public {

favoriteNumber = _favoriteNumber;

}


// getter function of favoriteNumber

function retrieve() public view returns(uint256) {

return favoriteNumber;

}


}

```


> - 創(chuàng)建了 people 數(shù)組,編制后會有一個`people`的按鈕,這里可以輸入`index`來找到對應(yīng)的 structure;

> - 同時,這里還寫了`addPerson`函數(shù)來添加 structure 到 array 中;

> - `memory`是一種 solidity 的存儲方式,這里表示的是臨時存儲,函數(shù)執(zhí)行完畢后數(shù)據(jù)會被清除。


### Memory, Storage and Calldata


EVM can access and store information in six places:


1. Stack

2. Memory: 可以被修改的臨時變量

3. Storage: 可以被修改的永久變量

4. Calldata: 不能被修改的臨時變量

5. Code

6. Logs


> Data location can only be specified for `array`, `struct` or `mapping` types

> `string` type actually is a `bytes` type


### Mappings


A mapping is a data structure where a key is "mapped" to a single value.


```sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;


// Contract: 0xd9145CCE52D386f254917e481eB44e9943F39138

contract SimpleStorage {

uint256 public favoriteNumber;


mapping(string => uint256) public nameToFavoriteNumber;


// Add `people` function

function addPerson(string memory _name, uint256 _favoriteNumber) public {

nameToFavoriteNumber[_name] = _favoriteNumber;

}


}

```


(32 小時最全課程)區(qū)塊鏈,智能合約 & 全棧 Web3 開發(fā)的評論 (共 條)

分享到微博請遵守國家法律
平安县| 喀喇| 临夏县| 盖州市| 巴彦淖尔市| 曲麻莱县| 安平县| 鸡西市| 突泉县| 通河县| 鹤山市| 尼勒克县| 白沙| 阿合奇县| 大化| 黄冈市| 崇礼县| 治多县| 汉川市| 三亚市| 思茅市| 丰原市| 都兰县| 富锦市| 湖南省| 灵台县| 安徽省| 常熟市| 广德县| 岳西县| 霞浦县| 南京市| 固安县| 温州市| 阿瓦提县| 临邑县| 泾源县| 郎溪县| 尼木县| 西青区| 罗江县|