Avatar
0
monkey Enlightened
monkey Enlightened
Danh sách các boot nodes của ethereum
Danh sách các boot nodes của ethereum
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
web3 js sử dụng hàm sign và hàm ecRecover làm chức năng đăng nhập
Những anh em nào yêu thích hoặc đã quen với lập trình javascript có thể sử dụng thư viện <a href="https://www.npmjs.com/package/web3" target="_blank">web3 js</a> để làm cơ chế đăng nhập thông qua hàm <code>sign</code> và <code>ecRecover</code>, ví dụ: <p> </p> <pre> const Web3 = require('web3'); const fs = require('fs'); const Strings = require('./strings'); let provider = new Web3.providers.HttpProvider("http://localhost:8545/"); let web3 = new Web3(provider); web3.eth.defaultAccount = "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f"; // contract address not account address var registerJson = '{' + ' "username": "dzung",' + ' "password": "123456",' + ' "email:": "dung@youngmonkeys.org"' + '}'; var registerHex = Strings.stringToHex(registerJson); web3.eth.personal.sign(registerHex, web3.eth.defaultAccount, "123") .then((signed) =&gt; { console.log("signed register: ", signed) web3.eth.personal.ecRecover(registerHex, signed) .then((address =&gt; console.log("the address: ", address))); }); </pre>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Sử dụng tài khoản ethereum để login cho các ứng dụng khác
Ethereum nói riêng hay blockchain nói chung đều sử dụng <strong>chữ ký số</strong> để ký và xác thực giao dịch, vậy nên chúng ta cũng có thể tận dụng cơ chế này cho phép người dùng có địa chí tài khoản etherum tạo được tài khoản trên hệ thông của chúng ta, các bước bao gồm: <p> </p> <ol start="1"> <li>Người dùng tạo một mật khẩu bất kỳ, chuyển mật khẩu này về dạng hex, sau đó ký với password này, ví dụ: </li> </ol> <p> </p> <pre> // 0x70617373776f7264 là hex của 'password' personal.sign("0x70617373776f7264", "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f") </pre> <p> </p> <p> Kết quả chúng ta sẽ nhận được 1 chuỗi ở phía client: <code>0xd8591710d40164116769731b960076fc901a05c7b0acec758e40dd3e6819a1d858540bc923db93f064c987ead6c6c41d62fcd6d874c06eba7092c23bd72631d61c</code> </p> <p> </p> <ol start="2"> <li>Tiếp theo client sẽ gửi lên server cả mật khẩu và chuỗi vừa nhận được </li> <li>Server sẽ giải mã chuỗi vừa nhận được với mật khẩu, và chúng ta sẽ nhận được tài khoản của người dùng, ví dụ: </li> </ol> <p> </p> <pre> personal.ecRecover("0x70617373776f7264", "0xd8591710d40164116769731b960076fc901a05c7b0acec758e40dd3e6819a1d858540bc923db93f064c987ead6c6c41d62fcd6d874c06eba7092c23bd72631d61c") </pre> <p> </p> <p> Kết quả chúng ta nhận được ở server: <code>0x3c31b4b9d6c24bad29498f99aaa6914231362c7f</code>. </p> <p> </p> <p> Tuy nhiên chúng ta thường có nhu cầu tạo tài khoản cho user vói nhiều hơn thông tin hơn, ví dụ: </p> <p> </p> <pre> { "username": "dzung", "password": "123456", "email:": "dung@youngmonkeys.org" } </pre> <p> </p> <ol start="1"> <li>Chúng ta có thể chuyển thông tin này thành dạng hex thế này: <code>0x7b0d0a202022757365726e616d65223a2022647a756e67222c0d0a20202270617373776f7264223a2022313233343536222c0d0a202022656d61696c3a223a202264756e6740796f756e676d6f6e6b6579732e6f7267220d0a7d</code> </li> </ol> <p> </p> <ol start="2"> <li>Client sẽ ký nó: </li> </ol> <p> </p> <pre> personal.sign("0x7b0d0a202022757365726e616d65223a2022647a756e67222c0d0a20202270617373776f7264223a2022313233343536222c0d0a202022656d61696c3a223a202264756e6740796f756e676d6f6e6b6579732e6f7267220d0a7d", "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f") </pre> <p> </p> <p> Kết quả client sẽ nhận được chuỗi: <code>0x120f5a9c0bff5d7997ac166960c2bbf7ea8c44cbe9c3640c17017ebe33f864327b7e8fa1b92edefc5e04dbf4f4431c73fde0bbe107d4ff87d6f361a961d5d8fb1c</code> </p> <p> </p> <ol start="3"> <li>Client gửi cả chuỗi hex và chuỗi vừa nhận được lên server </li> <li>Server sẽ giải mã chuỗi vừa nhận được: </li> </ol> <p> </p> <pre> personal.ecRecover("0x7b0d0a202022757365726e616d65223a2022647a756e67222c0d0a20202270617373776f7264223a2022313233343536222c0d0a202022656d61696c3a223a202264756e6740796f756e676d6f6e6b6579732e6f7267220d0a7d", "0x120f5a9c0bff5d7997ac166960c2bbf7ea8c44cbe9c3640c17017ebe33f864327b7e8fa1b92edefc5e04dbf4f4431c73fde0bbe107d4ff87d6f361a961d5d8fb1c") </pre> <p> </p> <p> Kết quả server sẽ nhận được: <code>0x3c31b4b9d6c24bad29498f99aaa6914231362c7f</code> </p> <p> </p> <ol start="5"> <li>Server sẽ lưu lại toàn bộ thông tin vào database và lần kế tiếp user sẽ có thể đăng nhập qua username, email hay địa chỉ ví đều được</li></ol>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Ethereum gas limit và gas price dùng để làm gì?
Trong ethereum thì gas limit và gas price dùng để tính ra tiền phí (eth) mà một giao dịch phải trả. Từ tháng 8 2021 thì cách tính phí giao dịch sẽ kiểu này: <p> </p> <ul> <li>Giả sử Alice gửi cho Bob 1 ETH với gas limit <code>21,000</code> units và gas price là <code>200 gwei </code>, thì tổng tiền phí sẽ là: <code>Gas units (limit) <em>Gas price per unit i.e 21,000</em> 200 = 4,200,000 gwei hoặc 0.0042 ETH</code> </li> <li>Khi Alice gửi tiền, <code>1.0042 ETH</code> sẽ được trừ vào tài khoản của Alice. Bob sẽ được ghi có <code>1.0000 ETH</code>. Máy đào sẽ nhận được <code>0,0042 ETH</code>. </li></ul> <p> </p> <p> Các máy đào cũng sẽ ưu tiên xác thực trước cho các giao dịch trả phí cao, vậy nên nếu cần giao dịch nhanh, bạn sẽ cần set gas limit hoặc giá gas cao lên </p> <p> </p> <p> Tham khảo: </p> <p> </p> <ol start="1"> <li><a href="https://ethereum.org/en/developers/docs/gas/" target="_blank">Tài liệu chính thức</a> </li> <li><a href="https://github.com/ethereum/go-ethereum/blob/master/consensus/misc/eip1559.go#L55" target="_blank">Code tính phí</a></li></ol>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Tạo một giao dịch chuyển tiền trong mạng ethereum private
Để tạo một giao dịch chuyển tiền trong mạng ethereum private, chúng ta có thể thực hiện các bước sau: <p> </p> <ol start="1"> <li>Tạo sẵn 1 tài khoản với mật khẩu tuỳ ý, ví dụ <code>123</code> </li> <li>Khởi tạo 1 mạng private với genesis block và tài khoản vừa tạo kiểu thế này: </li> </ol> <pre> { "config": { "chainID" : 10, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0 }, "difficulty": "1", "gasLimit": "9999999", "nonce": "0xdeadbeefdeadbeef", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "alloc": { "0x2b6fe850895f7656453bd282f6ffb0146b2e0ec3": { "balance": "30000" } } } </pre> <ol start="3"> <li>Tạo 1 tài khoản mới: <code>personal.newAccount()</code> </li> <li>Liệt kê danh sách tài khoản: <code>personal.listAccounts</code> </li> <li>Kiểm tra coin trong tài khoản: <code>eth.getBalance(eth.accounts[0])</code> </li> <li>Start miner: </li> </ol> <pre> miner.setEtherbase(eth.accounts[0]) miner.start() </pre> <ol start="7"> <li>Unlock account có tiền: <code>personal.unlockAccount(eth.accounts[0])</code> </li> <li>Tạo transaction: <code>var tx = {from: eth.accounts[0], to: eth.accounts[1], value: 100}</code> </li> <li>Send transaction: <code>personal.sendTransaction(tx, "123")</code> </li> <li>Kiểm tra tài khoản nhận được tiền chưa: <code>eth.getBalance(eth.accounts[1])</code> </li> <li>Kết quả chúng ta có: </li> </ol> <p> </p> <pre> &gt; personal.sendTransaction(tx, "123") "0xa7af127928c90250b6fcfbd93f79502e0131b8aea4a2bba2cfbbe92e573914df" &gt; eth.getBalance(eth.accounts[1]) 100 </pre>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Deploy ERC20 (smart contract cho ICO) lên mạng private
Dể deploy ERC20 (smart contract cho ICO) lên mạng private, chúng ta cần trải qua các bước sau: <p> </p> <ol start="1"> <li>Tải ERC20 contract <a href="https://github.com/ethereum-optimism/Truffle-ERC20-Example/tree/master/contracts" target="_blank">tại đây</a> </li> </ol> <p> </p> <ol start="2"> <li>Sửa file <code>truffle-config.js</code> thế này: </li> </ol> <p> </p> <pre> module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*", gas: 0, from: "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f" } }, compilers: { solc: { version: "0.7.6" } } }; </pre> <p> </p> <ol start="3"> <li>Sửa file <code>1_initial_migration.js</code> thế này: </li> </ol> <p> </p> <pre> const ERC20 = artifacts.require("ERC20"); module.exports = function (deployer) { const tokenName = 'My First Coin'; const tokenSymbol = 'MFC'; const tokenDecimals = 1; deployer.deploy( ERC20, 10000, tokenName, tokenDecimals, tokenSymbol, { gasPrice: 0 } ); }; </pre> <p> </p> <ol start="4"> <li>Chạy truffle compile </li> <li>Chạy trufle migrate </li> </ol> <p> </p> <ol start="6"> <li>Sau khi đã deploy contract thành công chúng ta sẽ chạy <code>truffle console</code> và gọi thử các lệnh: </li> </ol> <p> </p> <pre> let contract = await ERC20.deployed() contract.totalSupply() contract.transfer("0xf6de26f382078d34446b133fd54191fe49c77273", 1000) contract.balanceOf("0xf6de26f382078d34446b133fd54191fe49c77273") </pre> <p> </p> <p> Kết quả chúng ta sẽ nhận được: </p> <p> </p> <pre> truffle(development)&gt; contract.totalSupply() BN { negative: 0, words: [ 10000, ], length: 1, red: null } truffle(development)&gt; contract.transfer("0xf6de26f382078d34446b133fd54191fe49c77273", 1000) .... truffle(development)&gt; contract.balanceOf("0xf6de26f382078d34446b133fd54191fe49c77273") BN { negative: 0, words: [ 1000, ], length: 1, red: null } </pre>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Sử dụng smart contract trong mạng etherum với web3js
Giả sử contract của chúng ta có nội dung thế này: <p> </p> <pre> // SPDX-License-Identifier: MIT pragma solidity &gt;=0.4.22 &lt;0.9.0; contract Migrations { string public _message; uint public _last_completed_migration; function Hello() public{ _message = &quot;Hello World!&quot;; } function setCompleted(uint completed) public { _last_completed_migration = completed; } function message() public view returns(string memory) { return _message; } function lastCompletedMigration() public view returns (uint) { return _last_completed_migration; } } </pre> <p> </p> <p> Và chúng ta đã deploy contract truffle ở lần trước rồi nhé. </p> <p> </p> <ol start="1"> <li>Để sử dụng smart contract cho mục đích cá nhân hoặc test chúng ta có thể sử dụng truffle console: </li> </ol> <p> </p> <ol start="1"> <li> <ol start="1"> <li>Chạy lệnh: <code>truffle console</code> cho mạng private hoặc <code>truffle console --network ropsten</code> (xem danh sách các network trong file <code>truffle-config.js</code>) </li></ol></li> <li> <ol start="2"> <li>Chạy các lệnh sau trong console: </li></ol></li> </ol> <p> </p> <pre> let contract = await Migrations.deployed() contract.Hello() contract.message() </pre> <p> </p> <ol start="1"> <li> <ol start="3"> <li>Kết quả chúng ta nhận được: 'Hello World!' </li></ol></li> </ol> <p> </p> <ol start="2"> <li>Tuy nhiên thường thì muốn làm ứng dụng để phục vụ cho nhiều người, trong đó có các ứng dụng web, chúng ta có thể sử dụng web3.js. Ở đây mình sẽ viết ứng dụng node.js chạy console cho đơn giản: </li> </ol> <p> </p> <ol start="2"> <li>1 Khởi tạo project node js với file <code>package.json</code> thế này: </li> </ol> <p> </p> <pre> { "name": "eth-webb3js", "version": "1.0.0", "dependencies": { "fs": "0.0.1-security", "web3": "^1.6.0" }, "scripts": { "start": "node main.js" } } </pre> <p> </p> <ol start="2"> <li>2 Tạo file main.js thế này: </li> </ol> <p> </p> <pre> const Web3 = require('web3'); const fs = require('fs'); let provider = new Web3.providers.HttpProvider("http://localhost:8545/"); let web3 = new Web3(provider); web3.eth.defaultAccount = "0xa9f6009507ef930c67b98f7a12cb0ca4321aaadb"; // change by your contract address not account address let contractJson = fs.readFileSync("../truffle/build/contracts/Migrations.json").toString().trim(); let abi = JSON.parse(contractJson).abi; web3.eth.personal.unlockAccount("0x3c31b4b9d6c24bad29498f99aaa6914231362c7f", "123", 600) // change by your account address .then(console.log('Account unlocked!')); let contract = new web3.eth.Contract(abi, web3.eth.defaultAccount); contract.methods.Hello().call().then(console.log); contract.methods.message().call().then(console.log); </pre> <p> </p> <ol start="2"> <li>3 Sau khi setup xong, chúng ta sẽ có cấu trúc thư mục thế này: </li> </ol> <p> </p> <img src="https://stackask.com/wp-content/uploads/2021/11/Screen-Shot-2021-11-05-at-9.41.18-AM.png" alt="" class="alignnone size-full wp-image-2956" /> <p> </p> <ol start="2"> <li>4 Chạy lệnh <code>npm start</code> và chúng ta sẽ được kết quả thế này: </li> </ol> <p> </p> <pre> &gt; node main.js Account unlocked! Result {} Hello World! </pre>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Deploy contract lên mạng Ropsten test net
Để deploy contract lên mạng Ropsten test net, chúng ta cần thực hiện các bước sau: <p> </p> <ol start="1"> <li>Tạo project truffle </li> <li> <ol start="1"> <li>tạo thư mục truffle: <code>mkdir truffle</code> </li></ol></li> <li> <ol start="2"> <li><code>cd truffle</code> </li></ol></li> <li> <ol start="3"> <li><code>truffle init</code> </li></ol></li> </ol> <p> </p> <ol start="2"> <li>Cập nhật file <code>Migrations.sol</code> </li> </ol> <p> </p> <pre> // SPDX-License-Identifier: MIT pragma solidity &gt;=0.4.22 &lt;0.9.0; contract Migrations { string public message; uint public last_completed_migration; function Hello() public{ message = &quot;Hello World!&quot;; } function setCompleted(uint completed) public{ last_completed_migration = completed; } } </pre> <ol start="3"> <li>Tạo 1 tài khoản trên metamask và hãy lưu lại seedphase vào file <code>.secret</code> vào trong project <code>truffle</code> </li> <li>Request eth từ các nhà hảo tâm, nếu bạn cần hãy để lại tài ở comment khoản và mình sẽ chuyển cho bạn </li> <li>Tạo một dự án tại <a href="https://infura.io/" target="_blank">https://infura.io/</a> </li> <li>Bỏ comment và sửa đoạn này trong file <code>truffle-config.js</code> </li> </ol> <p> </p> <pre> ropsten: { provider: () =&gt; new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/{projectId vừa tạo}`), network_id: 3, gas: 5500000, confirmations: 2, timeoutBlocks: 200, skipDryRun: true } </pre> <p> </p> <ol start="7"> <li>Compile contract: <code>truffle compile</code> </li> <li>Deploy contract: <code>truffle migrate --network ropsten</code> </li> <li>Kết quả chúng ta nhận được: </li> </ol> <p> </p> <pre> 1_initial_migration.js ====================== Deploying 'Migrations' ---------------------- &gt; transaction hash: &lt;a href="https://ropsten.etherscan.io/tx/0x5f95932408cfcb54c0522637d17ce6f2fd2ce1ef5829139a3c169fbce91f9f71" target="_blank"&gt;0x5f95932408cfcb54c0522637d17ce6f2fd2ce1ef5829139a3c169fbce91f9f71&lt;/a&gt; Summary ======= &gt; Total deployments: 1 &gt; Final cost: 0.000418759097796939 ETH </pre> <p> </p> <p> Tham khảo: </p> <p> </p> <ol start="1"> <li><a href="https://www.trufflesuite.com/guides/using-infura-custom-provider" target="_blank">https://www.trufflesuite.com/guides/using-infura-custom-provider</a> </li> <li><a href="https://www.geeksforgeeks.org/deploying-smart-contract-on-test-main-network-using-truffle/" target="_blank">https://www.geeksforgeeks.org/deploying-smart-contract-on-test-main-network-using-truffle/</a></li></ol>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Tạo ethereum smart contract đơn giản trong mạng private
<ol start="1"> <li>tạo file genesis.json </li> </ol> <p> </p> <pre> { "config": { "chainId": 15, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0 }, "difficulty": "400000", "gasLimit": "2100000", "alloc": {} } </pre> <p> </p> <ol start="2"> <li>khởi tạo blockchain: <code>geth --datadir . init genesis.json</code> </li> </ol> <p> </p> <ol start="3"> <li>khởi động node <code>geth --syncmode fast --allow-insecure-unlock --cache 512 --ipcpath <s>/Library/Ethereum/geth.ipc --networkid 1234 --datadir . --http --http.api "personal,eth,net,web3,miner" --http.corsdomain "<em>" --nodiscover</code> </em></s></li> </ol> <p> </p> <ol start="4"> <li>tạo account đầu tiên: <code>geth --datadir . account new</code> </li> </ol> <p> </p> <ol start="5"> <li>khởi động geth console: <code>geth attach http://localhost:8545/</code> </li> </ol> <p> </p> <ol start="5"> <li>1 chạy lệnh để kiểm tra balance: <code>eth.getBalance(eth.accounts[0])</code> </li> </ol> <p> </p> <ol start="5"> <li>2 chạy lệnh để unlock account: <code>personal.unlockAccount(eth.accounts[0])</code> </li> </ol> <p> </p> <ol start="5"> <li>3 chạy lệnh để set ethbase: <code>miner.setEtherbase(eth.accounts[0])</code> </li> </ol> <p> </p> <ol start="5"> <li>4 start miner: <code>miner.start()</code> </li> </ol> <p> </p> <ol start="6"> <li>tạo thư mục truffle: <code>mkdir truffle</code> </li> </ol> <p> </p> <ol start="7"> <li><code>cd truffle</code> </li> </ol> <p> </p> <ol start="8"> <li>khởi tạo module, chạy lệnh: <code>truffle init</code>. Kết quả chúng ta có thự mục với cấu trúc: </li> </ol> <p> </p> <img src="https://stackask.com/wp-content/uploads/2021/11/Screen-Shot-2021-11-03-at-8.41.12-AM.png" alt="" class="alignnone size-full wp-image-2938" /> <p> </p> <ol start="9"> <li>Cập nhật file <code>Migrations.sol</code> </li> </ol> <p> </p> <pre> // SPDX-License-Identifier: MIT pragma solidity &gt;=0.4.22 &lt;0.9.0; contract Migrations { string public message; uint public last_completed_migration; function Hello() public{ message = "Hello World!"; } function setCompleted(uint completed) public{ last_completed_migration = completed; } } </pre> <p> </p> <ol start="10"> <li>Cập nhât file <code>truffle-config.js</code> </li> </ol> <p> </p> <pre> module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*", gas: 1192085, from: "0x3c31b4b9d6c24bad29498f99aaa6914231362c7f" } } }; </pre> <p> </p> <ol start="11"> <li>Chạy lệnh: <pre>truffle compile</pre> </li> </ol> <p> </p> <ol start="12"> <li>Chạy lệnh: <pre>truffle migrate</pre> </li> </ol> <p> </p> <p> Nếu gặp lỗi này: <code>"Migrations" -- Returned error: authentication needed: password or unlock.</code> thì chạy lại lệnh: <code>personal.unlockAccount(eth.accounts[0])</code> </p> <p> </p> <ol start="13"> <li>Gọi đến contract thông qua truffle, chạy lệnh: <code>truffle console</code> </li> </ol> <p> </p> <ol start="14"> <li>Gọi thử contract vừa tạo: </li> </ol> <p> </p> <pre> let contract = await Migrations.deployed() contract.Hello() contract.message.call() </pre> <p> </p> <p> Kết quả chúng ta có: </p> <p> </p> <pre> truffle(development)&gt; contract.Hello() { tx: '0xdf5fa89e5e71fac06ae50cdf4e44ac91e0c726d89176d838cc4b7efbb9e23402', ..... logs: [] } </pre> <p> </p> <pre> truffle(development)&gt; contract.message() 'Hello World!' </pre>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Tạo một ethereum chain mới
<ol start="1"> <li>Chạy geth thông tường </li> <li>Tạo sẵn 2 tài khoản </li> <li>Tắt geth đi </li> <li>Tạo một thư mục mới ví dụ <code>/Users/monkey/geth</code> </li> <li>Tạo 1 genesis block trong thư mục <code>/Users/monkey/geth</code> kiểu: </li> </ol> <p> </p> <pre> { "config": { "chainId": 15, "homesteadBlock": 0 }, "difficulty": "1", "gasLimit": "9999999", "nonce": "0xdeadbeefdeadbeef", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "alloc": { "tài khoản đầu tiên bạn đã tạo": { "balance": "30000" }, "tài khoản thứ 2 bạn đã tạo": { "balance": "50000" } } } </pre> <p> </p> <ol start="6"> <li>Copy thư mục keystore từ thư mục của Ethereum vào thư mục <code>/Users/monkey/geth</code> </li> </ol> <p> </p> <ol start="7"> <li>Chạy lệnh khởi tạo: </li> </ol> <p> </p> <code>geth --datadir . init genesis.json</code> <p> </p> <ol start="8"> <li>Chạy lệnh để start local node: </li> </ol> <p> </p> <code>geth --syncmode fast --cache 512 --ipcpath <s>/Library/Ethereum/geth.ipc --networkid 1234 --datadir . --http --http.api personal,eth,net,web3</code> <p> </p> <ol start="9"> <li>Thử test bằng cách gọi curl: </li> </ol> <p> </p> <pre> curl --location --request GET 'http://localhost:8545/' \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "method":"eth_accounts", "params":[], "id":1 }' </pre> <p> </p> <ol start="10"> <li>Kiểm tra thử balance của 1 tài khoản: </li> </ol> <p> </p> <pre> curl --location --request GET 'http://localhost:8545/' \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "method":"eth_getBalance", "params":[ "địa chỉ tài khoản", "latest" ], "id":1 }' </pre> <p> </p> <p> Tham khảo thêm <a href="https://www.skcript.com/svr/genesis-block-ethereum/" target="_blank">tại đây</a>. </p></s>
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Tạo tài khoản ethereum cho dev
<ol start="1"> <li>Để tạo tài khoản ethereum qua HTTP bạn có thể dùng câu lệnh này: </li> </ol> <p> </p> <pre> curl --location --request POST 'http://localhost:8545/' \ --header 'Content-Type: application/json' \ --data-raw '{ "jsonrpc":"2.0", "method":"personal_newAccount", "params":["password"], "id":1 }' </pre> <p> </p> <p> Chi tiết hơn bạn có thể tham khảo <a href="https://ethereum.stackexchange.com/questions/1413/how-can-i-make-new-account-by-json-rpc" target="_blank">tại đây</a>. </p> <p> </p> <ol start="2"> <li>Sau khi tạo tài khoản xong thì thông tin tài khoản sẽ nằm tại thư mục: </li> </ol> <p> </p> <code><s>/.ethereum</code> trên Linux <code></s>/Library/Ethereum</code> trên MacOS X <code><s>/AppData/Roaming/Ethereum</code> trên Windows <p> </p> <p> Câu trả lời chi tiết hơn có thể tham khảo <a href="https://ethereum.stackexchange.com/questions/6550/how-can-i-find-my-chaindata-folder" target="_blank">tại đây</a> </p> <p> </p> <p> Nếu bạn không muốn dùng curl, bạn có thể sử dụng geth console: </p> <p> </p> <ol start="1"> <li>khởi động geth console, chạy lệnh: <code>geth attach http://127.0.0.1:8543</code> </li> <li>chạy lệnh tạo tài khoản trên geth console: <code>personal.newAccount('mật khẩu của bạn')</code> </li> <li>chạy lệnh unlock tài khoản (tuỳ chọn): <code>personal.unlockAccount('tài khoản vừa tạo', "mật khẩu")</code> </li> </ol> <p> </p> <p> Còn nếu bạn lo lắng môi trường web với http không an toàn, bạn có thể sử dụng geth để tạo tài khoản bằng lệnh: <code>geth account new</code> </p></s>
Answer
Avatar
1
monkey Enlightened
monkey Enlightened
Bắt đầu làm quen với ethereum từ đâu
<ol start="1"> <li>Pull <a href="https://github.com/ethereum/go-ethereum" target="_blank">geth</a> về và làm theo hướng dẫn tại README.md để build </li> <li>Chạy câu lệnh này sau khi build xong để enable http api: </li> </ol> <code>./build/bin/geth --http --http.api personal,eth,net,web3</code> <ol start="3"> <li>Gọi thử 1 vài <a href="https://documenter.getpostman.com/view/4117254/ethereum-json-rpc/RVu7CT5J#7218b6e7-5e7f-da59-fe48-17838cce9731" target="_blank">API</a> đã được tổng hợp sẵn trên postman </li> <li>Tham khảo <a href="https://geth.ethereum.org/docs/getting-started" target="_blank">tài liệu chính thức</a> của ethereum </li> <li>Hỏi stackask nếu bạn có bất kì thắc mắc nào.</li></ol>
Answer