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:
  1. Tạo project truffle
  2. 1. tạo thư mục truffle: <code>mkdir truffle</code>
  3. 2. <code>cd truffle</code>
  4. 3. <code>truffle init</code>
  5. Cập nhật file <code>Migrations.sol</code>
    // 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;
        }
    }
    
  1. 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>
  2. 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
  3. Tạo một dự án tại <a href="https://infura.io/" target="_blank">https://infura.io/
  4. Bỏ comment và sửa đoạn này trong file <code>truffle-config.js</code>
    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
     }
     

  1. Compile contract: <code>truffle compile</code>
  2. Deploy contract: <code>truffle migrate --network ropsten</code>
  3. Kết quả chúng ta nhận được:

 1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   &gt; transaction hash:    <a href="https://ropsten.etherscan.io/tx/0x5f95932408cfcb54c0522637d17ce6f2fd2ce1ef5829139a3c169fbce91f9f71" target="_blank">0x5f95932408cfcb54c0522637d17ce6f2fd2ce1ef5829139a3c169fbce91f9f71</a>

Summary
=======
&gt; Total deployments:   1
&gt; Final cost:          0.000418759097796939 ETH
 

Tham khảo:

  1. <a href="https://www.trufflesuite.com/guides/using-infura-custom-provider" target="_blank">https://www.trufflesuite.com/guides/using-infura-custom-provider
  2. <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/
  • Answer
blockchain ethereum ropssten
Remain: 5
1 Answer
Avatar
monkey Enlightened
monkey Enlightened
Sharing
  • 0
  • Reply