BlockChain區塊鏈
  • 本書簡介
  • 區塊鏈運作原理
  • Bitcoin介紹
    • 簡介
    • Bitcoin其他知識
  • Bitcoin原理與實作
  • BitcoinJS
    • BTC 地址格式種類
    • 從 Mnemonic 轉為地址
  • Serverless 架構實作
  • Docker常用指令
  • ethereum初探
    • ethereum歷史
    • EVM
  • ethereum PoS 節點架設
  • ethereum(Docker)
  • ethereum(Geth)
    • Parity
  • ethereum(智能合約)
    • 合約測試 Unit Test
    • DAO
    • 可升級合約
    • 使用合約進行 multiswap
    • 合約安全
    • 開發工具
    • Hardhat 教學
      • Hardhat 寫測試
    • ERC-721 範例
      • 白名單機制
    • OpenZeppelin 合約 library
    • Truffle
    • 合約部屬
    • solidity 教學
  • ethereum(Dapp)
    • 相關 SDK
    • Multicall
    • Ethers.js 使用
    • Remix IDE
    • web3.js 使用
    • 在網頁上使用 web3 並操作區塊鏈
      • solidity筆記
  • Hyperledger Fabric
  • blockchainDB
  • 挖礦程式使用教學
    • 門羅幣/Monero (XMR)
  • Bitfinex API 使用
  • FTX API
  • CCXT 通用交易所 API
  • Solana 教學
  • Ethereum BigQuery
  • The Graph
    • yaml 定義
    • mapping 語法
    • Schema 定義
    • Query 範例
    • Unit test
  • DeFi 筆記
    • MEV 相關
    • Dex 聚合
    • Yearn
    • Curve
    • Uniswap
      • Swap 互動
    • AAVE、Compound
      • Compound 原理
      • AAVE 合約開發
Powered by GitBook
On this page
  • 簡介:
  • 產生乙太幣地址
  • 常見名詞:
  • 相關實用網站
  • Testnet
  • METAMASK
  • API Provider
  • 線上錢包(類似線上版的MIST)
  • 共識機制介紹
  • Block difficulty
  • Ethereum Gas 計算
  • 獲取地址在特定時間的 Token 餘額

Was this helpful?

ethereum初探

PreviousDocker常用指令Nextethereum歷史

Last updated 2 years ago

Was this helpful?

簡介:

以太坊(英語:Ethereum)是一個開源且具有智慧合約區塊鏈平台,設計上是為了解決比特幣擴展性不足的問題,以太坊區塊鏈上的代幣稱為以太幣(Ether),代碼為ETH

合約:

合約是一個活在以太坊系統內的自動代理人,他有一個自己的乙太幣地址,當用戶向合約的地址發送一筆交易後,該合約就被激活,然後根據交易中的額外信息,合約會運行自身的代碼,最後返回一個結果,這個結果可能是從合約的地址發出另外一筆交易

查看交易資訊:

產生乙太幣地址

const crypto = require("crypto");
const ecdh = crypto.createECDH("secp256k1");
const sha3 = require("js-sha3");

var hash2 = crypto.randomBytes(32).toString("hex");
console.log("--------");
console.log("私鑰");
console.log(hash2.toString("hex")); //私鑰,64位十六進制數 //使用hash2.toString('hex')即可看到16進位字串
console.log("--------");

// ECDH和ECDSA產生公私鑰的方式都相同
var publickey = ecdh.setPrivateKey(hash2, "hex").getPublicKey("hex");
console.log("公鑰");
console.log(publickey); //公鑰(通過橢圓曲線算法可以從私鑰計算得到公鑰)
console.log("--------");

var sha3_256Key = sha3.keccak256(Buffer.from(publickey, "hex").slice(1)); // pubkey 轉為 buffer 後移除第一位

var address = sha3_256Key.substring(24, sha3_256Key.length); // 取後40字

var address = "0x" + address; //
console.log(address);

常見名詞:

Dapp:

A Dapp (‘decentralized app’) consists of two parts: a frontend, written in HTML, and a backend (think of it as the ‘database’ for your frontend). 以太坊社區把基於智能合約的應用稱為去中心化的應用程序(Decentralized App)。DApp的目標是(或者應該是)讓你的智能合約有一個友好的界面

geth:

geth is the the command line interface for running a full ethereum node implemented in Go.

簡單說即為一個會回應json格式的server

IPC:

為系統中兩個兩個執行緒互相傳遞資料的方法

Ethash:

以太幣(ether)的挖礦算法叫做Ethash, 又名Dashimoto (Dagger-Hashimoto),是Hashimoto算法結合Dagger之後產成的一個變種

Dag:

EVM:

以太坊虛擬機,輕量級虛擬機環境,是以太坊中智能合約的運行環境

Gas:

燃料,每執行一條合約指令會消耗一定的燃料,當某個交易還未執行結束,而燃料消耗完時,合約執行終止並回滾(rollback)狀態,可與ether進行換算,但不可交易。

Gas Price: 每單位Gas多少錢( 會變動 )

Gas Limit: 多少單位個Gas( 通常不會變動 )

交易手續費 Tx Fees = Gas Limit * Gas Price

Ether單位

相關實用網站

Testnet

METAMASK

chrome的plugin,可以操作ethereum

API Provider

線上錢包(類似線上版的MIST)

安裝metamask後可以打開此網站,之後即可讀取本地錢包資料

並且使用metamask切換network

共識機制介紹

POW(Proof of Work,工作證明)是指獲得多少貨幣,取決於你挖礦貢獻的工作量,即為一般的礦機或顯卡挖礦

POS(Proof of Stake,股權證明)根據你持有貨幣的量和時間進行利息分配的制度,在POS模式下,挖礦收益正比於你的幣齡,而與電腦的計算性能無關,幣齡即為持有乙太幣的時間

PoA ( Proof of Authority) 有別於PoW (Proof-of-Work)需要解數學難題來產生block,PoA是依靠預設好的Authority nodes,負責產生block。 可設定Authority node數量。可指定產生block的時間等

Block difficulty

礦工挖礦的難度,當礦工增加時難度會根據算法而增加。

Ethereum Gas 計算

簡單來說:

Gas used * gas price * (gwei to eth)

117159 * 52 * 0.000000001 =0.006092268

上面的 52 可以從下圖去查看 med gas price

gas 為以太坊上交易的手續費,會轉換成 eth 計算費用。

分為 Transaction costs 與 Execution costs

Transaction costs 總共有以下四種情況需要支付:

  1. (一般交易) the base cost of a transaction (21000 gas)

  2. (合約部署) the cost of a contract deployment (32000 gas)

  3. the cost for every zero byte of data or code for a transaction.

  4. the cost of every non-zero byte of data or code for a transaction.

Execution costs 則為執行合約時運算所需要消耗的資源而定,可參考下表

以上表來說 value 指的是 gas unit 或 gas limit(多少單位的 gas),所以以太坊交易手續費計算方式則類似如下: 21000 (Gas Limit) x 50 Gwei (Gas Price)= 1050000 Gwei

gas price 一般用 Gwei 為單位,所以計算後交易手續費為(TX Fee) = 1050000 *0.000000001 ETH = 0.0010500 ETH

(小提醒:每天不同時段的 Gas price 會不同,依照網路上交易擁堵程度而定,通常白天時段的下午費用會比較低)

當前網路上之 Gas price 可到此查詢

獲取地址在特定時間的 Token 餘額

之後到 右上輸入剛產生的地址確認是正確的格式

JSON-PRC:

可參考:

1、以太坊官方網站:

2、以太坊原始碼(官方):

3、以太坊說明文件(官方):

4、以太坊網路狀態(官方): /

5、以太坊相關工具與資源網站(官方):

6、Solidity說明文件(官方):

7、以太坊網路掃描(官方):

8、以太坊官方部落格:

9、以太坊wiki百科:

10、以太坊中文愛好者網站:

11、以太坊的gitter的實時交流網站:

12、以太坊的官方論壇:

13、以太坊第三方強大的IDE(Solidity IDE):

14、以太坊開發框架Truffle說明書:

15、以太坊開發框架dapple說明書:

16、以太坊官方推薦開發框架Meteor說明書:

取得免費的ether 查看區塊情況

Aave testnet:

https://etherchain.org/
https://ethereum.stackexchange.com/questions/3542/how-are-ethereum-addresses-generated
https://etherscan.io/
https://github.com/ethereum/wiki/wiki/JSON-RPC
https://github.com/ethereum/wiki/wiki/JSON-RPC
https://zh.wikipedia.org/wiki/行程間通訊
http://albert-oma.blogspot.tw/2013/06/linux-ipc.html
https://github.com/ethereum/wiki/blob/master/Dagger-Hashimoto.md
https://github.com/ethereum/wiki/wiki/Ethash-DAG
http://ethdocs.org/en/latest/ether.html
https://ethereum.org/
https://github.com/ethereum/
http://www.ethdocs.org/en/latest/index.html
https://ethstats.Net
http://ether.fund/
http://solidity.readthedocs.io/en/latest/
http://etherscan.io/
https://blog.ethereum.org/
https://github.com/ethereum/wiki/wiki
http://ethfa​​ns.org/
https://gitter.im/orgs/ethereum/rooms
https://forum.ethereum.org/
https://live.ether.camp/
http://truffle.readthedocs.io/en/latest/
http://dapple.readthedocs.io/en/master/
https://github.com/ethereum/wiki/wiki/Dapp-using-Meteor
https://ropsten.ether.camp/transactions
http://faucet.ropsten.be:3001/
https://testnet.etherscan.io/
https://staging.aave.com/#/markets
https://metamask.io/
https://infura.io/#how-to
https://wallet.ethereum.org/
https://ethgasstation.info/
https://etherscan.io/tokencheck-tool
2Miners Mining PoolAltcoin Mining Pool for GPU and ASIC - 2Miners
Logo