Shardeum — Cara Menerapkan Kontrak Cerdas ERC-20 di Shardeum Menggunakan Truffle

Pengaturan Lingkungan Truffle

  1. NodeJS v12 atau yang lebih baru (tersedia di sini)
  2. Penginstal Paket Npm/Yarn (disertakan dengan Node)
  3. Windows, Linux atau Mac OS X

Memasang Truffle

npm install -g truffle

Membuat Proyek

mkdir testToken
cd testToken
truffle init
  1. contracts/: Direktori untuk kontrak Solidity
  2. migrations/: Direktori untuk file penyebaran yang dapat ditulis
  3. test/: Direktori untuk file pengujian untuk menguji aplikasi dan kontrak Anda
  4. truffle-config.js: File konfigurasi truffle
  5. build (terlihat setelah dikompilasi): Kontrak Soliditas yang dikompilasi dengan bytecode dan ABI

Buat Kontrak

npm install @openzeppelin/contracts
// SPDX-License-Identifier: MITpragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract testToken is ERC20 {
constructor(uint256 initialSupply) ERC20("testTkn", "TST") { _mint(msg.sender, initialSupply);
}
}

Kompilasi Kontrak

truffle compile

Migrasi Pengkodean

var test = artifacts.require("testToken");module.exports = function(deployer) {
// deployment
deployer.deploy(test, '10000000000000000000000');
};

Mengkonfigurasi Truffle Untuk Shardeum Liberty (Testnet)

  1. Buka truffle-config.js (terletak di direktori root)
  2. Perbarui dengan detail Shardeum Liberty (tersedia di sini)
const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard port (default: none)
network_id: "*", // Any network (default: none)
},
liberty: {
provider: () => new HDWalletProvider(mnemonic, `https://liberty10.shardeum.org/`),
network_id: 8080,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
}
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: "^0.8.0", // A version or constraint - Ex. "^0.5.0"
}
}
}
truffle migrate --network liberty
Starting migrations...
======================
> Network name: 'liberty'
> Network id: 8080
> Block gas limit: 20000000000 (0x4a817c800)
2_deploy.js
===========
Deploying 'testToken'
---------------------
> transaction hash: 0x9a3fcdb6d517d7cf0ee69f8076d020e1bba8cdd01378cc34eaf1030a7fdfc273
> Blocks: 0 Seconds: 8
> contract address: 0x4d63Ba5f3E48dbE7f2b1e459C74BE94B8d61e919
> block number: 11
> block timestamp: 1438271100
> account: 0xFa0B6609cd5d8fC19A1aC16311da1466FaF09978
> balance: 99.964878389908455424
> gas used: 1170047 (0x11da7f)
> gas price: 20 gwei
> value sent: 0.00429 ETH
> total cost: 0.02769094 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.02769094 ETH
Summary
=======
> Total deployments: 1
> Final cost: 0.02769094 ETH

--

--

Just ordinary Crypto 🖤 NFT!

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store