- Tạo project truffle
-
- tạo thư mục truffle:
mkdir truffle
- tạo thư mục truffle:
-
cd truffle
-
truffle init
- Cập nhật file
Migrations.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <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;
}
}
- Tạo 1 tài khoản trên metamask và hãy lưu lại seedphase vào file
.secretvào trong projecttruffle - 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
- Tạo một dự án tại https://infura.io/
- Bỏ comment và sửa đoạn này trong file
truffle-config.js
ropsten: {
provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/{projectId vừa tạo}`),
network_id: 3,
gas: 5500000,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
}
- Compile contract:
truffle compile - Deploy contract:
truffle migrate --network ropsten - Kết quả chúng ta nhận được:
1_initial_migration.js ====================== Deploying 'Migrations' ---------------------- > transaction hash: <a href="https://ropsten.etherscan.io/tx/0x5f95932408cfcb54c0522637d17ce6f2fd2ce1ef5829139a3c169fbce91f9f71" target="_blank">0x5f95932408cfcb54c0522637d17ce6f2fd2ce1ef5829139a3c169fbce91f9f71</a> Summary ======= > Total deployments: 1 > Final cost: 0.000418759097796939 ETH
Tham khảo: