How to Create A Cryptocurrency Token Using Smart Contract

Introduction

Ethereum

Creating A Smart Contract

 npm install -g truffle
truffle init
npm install @openzeppelin/contracts
pragma solidity ^0.8.2;import "@openzeppelin/contracts/token/ERC20/ERC20.sol";contract NiceToken is ERC20 {    constructor() ERC20("Nice Coin", "NICE") {}

function mint(address account, uint256 amount) public {
_mint(account, amount);
}
}
truffle compile

Setup Local Blockchain Network

module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*",
},
...

Deploying the Smart Contract to the Blockchain.

const NiceToken = artifacts.require("NiceToken")module.exports = async function (deployer) {   await deployer.deploy(NiceToken);

const niceToken = await NiceToken.deployed()
// Mint 200 NiceToken for the first account
await niceToken.mint(
'0x8D1be72BD7B79322D28C7185eB1346234c0a279b',
'200000000000000000000'
)
};
truffle migrate
1_initial_migration.js
======================
Deploying 'NiceToken'
---------------------
> transaction hash: 0x6cc049dc4ba3a2b35f6964e7e4c25adc78a1e4c98a198397a8411fd706dc7a2d
> Blocks: 0 Seconds: 0
> contract address: 0xdE928AC7259340545Ed8Fa290588a8b0076Ff9F4
> block number: 1
> block timestamp: 1642949701
> account: 0x8D1be72BD7B79322D28C7185eB1346234c0a279b
> balance: 99.97412728
> gas used: 1293636 (0x13bd44)
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.02587272 ETH

> Saving artifacts
-------------------------------------
> Total cost: 0.02587272 ETH

Visualizing Cryptocurrency In A Crypto Wallet

Conclusion

  • Created a Smart Contract for a new ERC-20 Token called “Nice”.
  • Deployed the Smart Contract to a local blockchain network.
  • Minted some tokens for an account.
  • Connected the local blockchain network to MetaMask Crypto Wallet.
  • Visualized the token balance using MetaMask Crypto Wallet for an account.

--

--

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