<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jack Yu on Medium]]></title>
        <description><![CDATA[Stories by Jack Yu on Medium]]></description>
        <link>https://medium.com/@luckyjack85?source=rss-14b3a85eb5b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Gk0i1EKXH88-4kAy.</url>
            <title>Stories by Jack Yu on Medium</title>
            <link>https://medium.com/@luckyjack85?source=rss-14b3a85eb5b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 09:05:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luckyjack85/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[一個簡單 Dapp 初探]]></title>
            <link>https://medium.com/@luckyjack85/%E4%B8%80%E5%80%8B%E7%B0%A1%E5%96%AE-dapp-%E5%88%9D%E6%8E%A2-6c01f80010bf?source=rss-14b3a85eb5b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c01f80010bf</guid>
            <category><![CDATA[ethereum-blockchain]]></category>
            <category><![CDATA[develop]]></category>
            <category><![CDATA[dapps]]></category>
            <dc:creator><![CDATA[Jack Yu]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 00:47:12 GMT</pubDate>
            <atom:updated>2018-12-05T00:51:52.875Z</atom:updated>
            <content:encoded><![CDATA[<p>大家好我們這篇文章要來討論一下, 在開發ethereum dapp 的時候大致的組織, 這裡是根據我的經驗, 述說一個我所理解的一個區塊鏈的應用大概組成的部分以及做的事情</p><p>先上圖, 這個圖就是這篇我會討論到的所有東西, 我會講一下每條線所代表的意義以及大概做的事情</p><blockquote>這篇會假設大家對於網站開發, 區塊鏈以及 Ethereum 有基本的了解</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9LT7rnRJOiTvwJezxHp6w.png" /><figcaption>Overall</figcaption></figure><blockquote>我的理解 : Dapp 就是 與區塊鏈溝通的一個應用程式 (Web, app)</blockquote><h4>A Simple Website</h4><p>以一個簡單的前後端分離的網站, 我所理解的東西大概就是有個前端 後端</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLIXq5ko6p5lo6p6szEdJQ.png" /><figcaption>Simple application</figcaption></figure><p>Client 端可以是 Web or App, Backend 可以讓Client 端 call api, 然後這個後端可以跟 DB 溝通這樣</p><p>如果是一些框架 nodejs express, php laravel, python Django, java Spring 那基本上事情都是server side處理掉, 並沒有所謂的前後端分離</p><p>當然如果只是個純粹的靜態網站也沒問題</p><p><strong>以下我將會以 javascript 作為主要開發語言的角度去敘述, 所有的後端都是 nodejs express, 所有的前端都是 web</strong></p><h4>名詞定義</h4><ol><li>Enode 可以透過http or websocket 與Ethereum 互動的節點, 主要有<a href="https://github.com/ethereum/go-ethereum"> go-ethereum</a> (golang) 以及 <a href="https://www.parity.io/">parity</a> (implement by Rust) 實做的 client 端,可以與其他節點進行同步</li><li>Web3js 為 javascript 在開發Dapp 時常使用的library , 目前版本為 1.0.0-beta.36, <a href="https://web3js.readthedocs.io/en/1.0/">web3.js</a></li></ol><p>以上這兩個東西之後會再補充</p><h4>與Ethereum 互動</h4><p>從我們要做的事情出發去理解, Dapp 做的事情基本上就是, 與 Ethereum 互動, 互動有兩種行為把資料讀出來 , 或是寫入以及更改</p><h4>讀取</h4><p>block, transaction, address , balance 每個都是資訊並且裡面有其相對應的資料是我們需要去讀取的, 讀取意味著不需要送 transaction 可以直接跟enode 拿, 以上資訊我們可以透過一些 library 例如 web3, 去進行比較抽象的操作</p><h4>寫入與更改</h4><p>那如果是要寫入或者是說進行更改呢? 我們會需要建立 或者說執行一個 transaction 我們來看一個transaction 的組成</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WzkNCqX66isSK_fcLrf2Ig.png" /><figcaption>A Simple Transaction</figcaption></figure><p>這是一筆erc20 transfer 的 transaction, Etherscan 幫我們把各個資訊都整理出來, 每個欄位都有其意義, TxHash, Block Height, Time Stamp, From, To, Gas Limit , Gas Price, Value, Nonce, Input Data 之後會再補上這些欄位的說明</p><p>你要做的事情是組裝一個 transaction, 有點像郵局匯款, 要填入適當的資訊櫃台人員才有辦法幫你處理, 不過 transaction 的互動對象是 EVM, 要正確地填入某些欄位, EVM才有辦法執行, 組裝的過程一樣可以透過一些library (例如 web3) , 用比較抽象的方式去組裝它</p><p>以上讀取與寫入, 歸類為以下操作</p><ol><li>讀資料 (Only chain data)<br>讀取 blocks info, transactions info, event log, user balance, user nounce, <em>不需要動用key</em></li><li>傳錢<br>指傳送ether 的行為 (不包含Token), <em>需要動用 key</em></li><li>Create Smart Contract (transaction 中 to 為空)<br>部屬智能合約, <em>需要動用key</em></li><li>Read Smart Contract (constant function)<br>讀取智能合約上的資料, 且其function 不須計算資源,<em> 不需要動用key</em></li><li>Interact with Smart Contract<br>更改變數, 執行bytecode, <em>需要動用key</em></li></ol><h4>以上</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ul9XAIiXJalZmS6c9fqV3A.png" /></figure><p>基本上來說與Ethereum 互動, 其中一種方式就是如同上圖, 透過 web3 組裝你的需求傳送給enode, enode 裡面會有 Ethereum 上的資料, 還有EVM 可以幫你執行你的 request</p><p>以下的討論基本上就是 Web3 要擺哪? Enode 要擺哪? 並且對應到各個不同的情況時的選擇</p><blockquote>然後強調一點 web3 不是必要的 library, 因為與Enode 互動只需要送 JSON-RPC 即可, web3 只是一個library 可以以較方便的方式組裝 JSON-RPC, 但為了方便討論所以我們以web3 舉例</blockquote><h4>Web3 &amp; Enode</h4><ol><li>Only Frontend</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mHTqhtH1R4RrtojU5xCQ5w.png" /><figcaption>Only Frontend</figcaption></figure><p>基本上現在大部分的 Dapp 就是這種架構, 只有個前端, 然後透過 web3js 與 enode 互動, 通常是使用 Metamask 提供的 Enode, 所以這種 Dapp 做的事情就是, 讀取Ethereum 上的資料, 然後送transaction</p><p>2. Frontend &amp; Backend with enode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n-twQv_ugDtaKKxpFvginQ.png" /><figcaption>Simple Frontend with Backend</figcaption></figure><p>這種是將 web3 以及 Enode 放在後端, 然後通常會自己維護一個 Enode, 好處是, 前端就不用做一堆麻煩事(encode, event listener), 前端基本上就是跟call api 一樣, 不太需要處理Ethereum 相關的事情, 比較麻煩的就是Enode 的管理</p><p>3. Etherscan api (Infura 也有提供類似的服務但我沒用過)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-BrvMMXetRUjVGkPCT5zw.png" /></figure><p><a href="https://etherscan.io/aboutus">Etherscan </a>是一個 Ethereum 的 Explorer , 我如果理解正確的話它是一間公司, 並且<em>技術極其頂尖</em>, 它的存在對開發者來說非常的重要, 並且它還提供了大量非常重要的資訊, Etherscan api 是指提供了一系列的<a href="https://etherscan.io/apis">api</a> 可以直接對Etherum 進行操作, 以及資訊的獲取, 說實在的真的好用, 但前提是你要知道如何使用 Ethereum JSON-RPC 的call, 並且你的應用是存在於 mainnet, Ropsten, Kovan, Rinkeby 這些公開鏈上 , 這api 超級方便</p><p>4. MetaMask</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FYA9noi1-jiOpg3d7yikNw.png" /><figcaption>MetaMask</figcaption></figure><p>簡單說明一下 MetaMask 做的事情, 管理key, 還有 提供 web3 以及enode, MetaMask 會在瀏覽器裡面inject web3 這個object, 然後裡面有個 currentProvider 的Object 提供了 enode 的 endpoint, 所以基本上就是 web3 enode 一把抓</p><h3>總結</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9LT7rnRJOiTvwJezxHp6w.png" /><figcaption>Overall</figcaption></figure><p>回到我們一剛開始那張圖, 我們來說明一下每條線說明<br>(Smart Contract 是長在 Ethereum裡面, 所以兩個東西畫在一起)</p><ol><li>API to backend</li><li>Enode to ethereum</li><li>Metamask to ethereum</li><li>Etherscan api</li></ol><p>最後我們來總結一下, Dapp 就是個與 Ethereum 互動的程式, 互動有讀取與寫入, web3 只是一個library來協助我們互動,並不是必要的, 重要的是你想要互動的訊息最後要傳到鏈上, Enode 是個與鏈互動的程式並且含有鏈的資料可以藉由同步(sync)獲得</p><p>之後如果有時間會再把幾個東西挑出來講, 今天這篇只講了比較大的東西, 每個部份都可以再繼續討論, 例如: 該如何管理key?, web3 提供了那些功能並且幫我們做掉那些事情?, Enode 在開發的時候有哪些選擇?, Etherscan 提供了那些資訊?, 如果不用 web3 那有沒有其他選擇?</p><p>感謝各位的閱讀, 若有講的不清楚的地方還請多多包涵</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c01f80010bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>