Avatar
1
Sơn Ngọc Beginner
Sơn Ngọc Beginner
AI sẽ thế nào khi Web3 hoàn thiện và phát triển
Khi mà web3 phát triển hoàn thiện, đồng nghĩa với việc data của user sẽ được public trên blockchain. Vậy liệu đây sẽ thuận lợi cho việc phát triển các Model AI không ạ?
Answer
Avatar
1
Sơn Ngọc Beginner
Sơn Ngọc Beginner
Security trong thế hệ web3
Chào mọi người, theo như em tìm hiểu thì trong thế hệ web3, user sẽ thực sự sở hữu data do mình tạo ra và không ai khác có thể thay đổi nó. Có đúng là để làm được điều này, thì mỗi user sẽ phải tạo 1 account trong blockchain network không ạ? Nếu đúng như vậy thì làm thế nào để ta có để bảo mật được các thông tin nhạy cảm của account ví dụ như private key ạ? Và khi thế hệ web3 phát triển thì sẽ ảnh hưởng thế nào đến các tập đoàn lớn sử dụng nhiều thông tin của user như Google, Facebook,... ?
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Blockchain: Deploy vả sử dụng smart contract từ web3 java client
Blockchain: Deploy vả sử dụng smart contract từ web3 java client
Answer
Avatar
0
monkey Enlightened
monkey Enlightened
Dự án NFT đơn giản với Metamask và Web3: Khởi tạo môi trường
Dự án NFT đơn giản với Metamask và Web3: Khởi tạo môi trường
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 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