harmonyos2-H2O:和谐ERC20

  • X5_331102
    了解作者
  • 110.4KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-13 04:16
    上传日期
和声2 水 和谐ERC20 概述 此示例项目可用于在 Harmony 的测试网上部署 ERC20 代币 先决条件 请阅读指南 安装 # install truffle $npm install -g truffle # clone this project $git clone https://github.com/harmony-one/H2O.git $cd H2O # install modules $npm install 编译智能合约 $truffle compile 将智能合约部署到 Harmony 的测试网 $truffle migrate --network testnet --reset Compiling your contracts... =========================== > Everything is up to date, there is nothing to compile. Migrations dry-run (simulation) =============================== > Network name:
H2O-master.zip
  • H2O-master
  • .gitignore
    914B
  • truffle-config.js
    3.2KB
  • package.json
    269B
  • package-lock.json
    25.2KB
  • mint_transfer_token.js
    1.6KB
  • .envSample
    998B
  • build
  • contracts
  • ERC20Detailed.json
    60.6KB
  • Roles.json
    88.4KB
  • MinterRole.json
    94.5KB
  • Migrations.json
    53.5KB
  • ERC20Mintable.json
    69KB
  • HarmonyERC20.json
    74.4KB
  • IERC20.json
    73.1KB
  • ERC20.json
    480.9KB
  • SafeMath.json
    142.1KB
  • LICENSE
    1KB
  • transfer.js
    1.9KB
  • show_balance.js
    1.4KB
  • README.md
    8.4KB
  • migrations
  • 2_deploy_HarmonyERC20.js
    398B
  • 1_initial_migration.js
    125B
  • contracts
  • Migrations.sol
    515B
  • HarmonyMintable.sol
    515B
  • HarmonyERC20.sol
    428B
内容介绍
# H2O Harmony ERC20 ## Overview This sample project can be used to deploy an ERC20 token on Harmony's Testnet ## Pre-requisites Please read the guideline for [Smart Contract Development using Truffle](https://app.gitbook.com/@harmony-one/s/docs-internal/v/v1.1.2/developers-1/which-one-are-you/smart-contract-devel/smart-contract-development-using-truffle) ## Install ```bash #install truffle $npm install -g truffle #clone this project $git clone https://github.com/harmony-one/H2O.git $cd H2O #install modules $npm install ``` ## Compile smart contract ```bash $truffle compile ``` ## Deploy smart contract to Harmony's testnet ```bash $truffle migrate --network testnet --reset Compiling your contracts... =========================== > Everything is up to date, there is nothing to compile. Migrations dry-run (simulation) =============================== > Network name: 'testnet-fork' > Network id: 2 > Block gas limit: 0x66916c 1_initial_migration.js ====================== Replacing 'Migrations' ---------------------- > block number: 236254 > block timestamp: 1570227191 > account: 0x3aea49553Ce2E478f1c0c5ACC304a84F5F4d1f98 > balance: 923.003096645399407586 > gas used: 246393 > gas price: 2 gwei > value sent: 0 ETH > total cost: 0.000492786 ETH ------------------------------------- > Total cost: 0.000492786 ETH 2_deploy_HarmonyERC20.js ======================== Replacing 'HarmonyERC20' ------------------------ > block number: 236256 > block timestamp: 1570227198 > account: 0x3aea49553Ce2E478f1c0c5ACC304a84F5F4d1f98 > balance: 923.000266111399407586 > gas used: 1388244 > gas price: 2 gwei > value sent: 0 ETH > total cost: 0.002776488 ETH ------------------------------------- > Total cost: 0.002776488 ETH Summary ======= > Total deployments: 2 > Final cost: 0.003269274 ETH Starting migrations... ====================== > Network name: 'testnet' > Network id: 2 > Block gas limit: 0x66916c 1_initial_migration.js ====================== Replacing 'Migrations' ---------------------- > transaction hash: 0x3be646bab73e1b6725f4e78a379db2c4227353d22732b411f43bce64312fd2ea > Blocks: 0 Seconds: 4 > contract address: 0x7b5B72fD8A1A4B923Fb12fF1f50b5C84F920278d > block number: 236255 > block timestamp: 1570227203 > account: 0x3aea49553Ce2E478f1c0c5ACC304a84F5F4d1f98 > balance: 923.003328038399407586 > gas used: 261393 > gas price: 1 gwei > value sent: 0 ETH > total cost: 0.000261393 ETH > Saving migration to chain. > Saving artifacts ------------------------------------- > Total cost: 0.000261393 ETH 2_deploy_HarmonyERC20.js ======================== Replacing 'HarmonyERC20' ------------------------ > transaction hash: 0xe4e7d027b24e328e5b79e3d026eb48a71c971fa112b6c74bef70e776128afa92 > Blocks: 0 Seconds: 4 > contract address: 0xf2c3b75dAB0e45652Bf0f9BD9e08d48b03c3926E > block number: 236257 > block timestamp: 1570227219 > account: 0x3aea49553Ce2E478f1c0c5ACC304a84F5F4d1f98 > balance: 923.001792771399407586 > gas used: 1493244 > gas price: 1 gwei > value sent: 0 ETH > total cost: 0.001493244 ETH > Saving migration to chain. > Saving artifacts ------------------------------------- > Total cost: 0.001493244 ETH Summary ======= > Total deployments: 2 > Final cost: 0.001754637 ETH (base) CBA-219302-MBP:H2O Xuan$ ``` ## List the smart contract on testnet ```bash $truffle networks Network: development (id: 2) No contracts deployed. Network: testnet (id: 2) HarmonyERC20: 0xf2c3b75dAB0e45652Bf0f9BD9e08d48b03c3926E Migrations: 0x7b5B72fD8A1A4B923Fb12fF1f50b5C84F920278d ``` ## Interact with smart contract with a custom javascript A custom javascript **mint_transfer.js** is used to mint and transfer token ```javascript var HarmonyERC20 = artifacts.require("HarmonyERC20"); //mint amount address const myAddress = "0x3aea49553Ce2E478f1c0c5ACC304a84F5F4d1f98"; //test account address, keys under //https://github.com/harmony-one/harmony/blob/master/.hmy/keystore/one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7.key const testAccount = "0x7c41e0668b551f4f902cfaec05b5bdca68b124ce"; const transferAmount = 2000000; module.exports = function() { async function getHarmonyERC20Information() { let instance = await HarmonyERC20.deployed(); let name = await instance.name(); let total = await instance.totalSupply(); let decimals = await instance.decimals(); let mybalance = await instance.balanceOf(myAddress); instance.transfer(testAccount, transferAmount); let testAccBalance = await instance.balanceOf(testAccount); console.log("HarmonyERC20 is deployed at address " + instance.address); console.log("Harmony ERC20 Information: Name : " + name); console.log("Harmony ERC20 Information: Decimals: " + decimals); console.log("Harmony ERC20 Information: Total : " + total.toString()); console.log("my address : " + myAddress); console.log("test account address : " + testAccount); console.log("my minted H2O balance is: " + mybalance.toString()); console.log("test account H2O balance is: " + testAccBalance.toString()); console.log("\ntransfered " + transferAmount.toString() + " from my address (minter) to test account"); } getHarmonyERC20Information(); }; ``` A custom javascript **show_balance.js** is used to show balance ```javascript var HarmonyERC20 = artifacts.require("HarmonyERC20"); //mint amount address const myAddress = "0x3aea49553Ce2E478f1c0c5ACC304a84F5F4d1f98"; //test account address, keys under //https://github.com/harmony-one/harmony/blob/master/.hmy/keystore/one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7.key const testAccount = "0x7c41e0668b551f4f902cfaec05b5bdca68b124ce"; const transferAmount = 2000000; module.exports = function() { async function getHarmonyERC20Information() { let instance = await HarmonyERC20.deployed(); let name = await instance.name(); let total = await instance.totalSupply(); let decimals = await instance.decimals(); let mybalance = await instance.balanceOf(myAddress); let testAccBalance = await instance.balanceOf(testAccount); console.log("HarmonyERC20 is deployed at address " + instance.address); console.log("Harmony ERC20 Information: Name : " + name); console.log("Harmony ERC20 Information: Decimals: " + decimals); console.log("Harmony ERC20 Information: Total : " + total.toString()); console.log("my address : " + myAddress); console.log("test account address : " + testAccount); console.log("my minted H2O balance is: " + mybalance.toString()); console.log("test account H2O balance is: " + testAccBalance.toString()); } getHarmonyERC20Information(); }; ``` ## Mint and send token to a test account ```bash $ truffle exec ./mint_transfer_token.js --network testnet Using network 'testnet'. HarmonyERC20 is deployed at address 0xbBE1E92631C8846ff729C09FD629F98544966c6A Harmony ERC20 Information: Name : HarmonyERC20 Harmony ERC20 Information: Decimals: 18 Harmony ERC20 Information: Total : 1000000000000000000000000 my address : 0x3aea49553Ce2E478f1c0c5ACC304a84F5F4d1f98 test account address : 0x7c41e0668b551f4f902cfaec05b5bdca68b124ce my minted H2O balance is: 1000000000000000000000000 test account H2O balance is: 0 transfered 2000000 from my address (minter) to test
评论
    相关推荐