ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
20221110 MetaCoin
Kenneth Hu
? I am a software developer , not trader.
? I am enthusiast, not expert.
? Ethereum, Bitcoin
? Email: Kenneth.hu@Hotmail.com
? Linkedin https://www.linkedin.com/in/hukenneth/
? Blockchain&Dapps meetup
? DeFi - Decentralized Finance, SG
Agenda
? 1. Introduction
? 2. Development software tools and environment
? 3. Create crypto currency
? 4. Create the user interface
? 5. Connect to wallet
? 6. Send crypto currency
? 7. Confirm receipt of virtual currency
? 8. ERC20
Architecture
Browser
Internet via HTTP(s)
Json RPC Interface
Web3.js
MetaCoin Dapp
MetaCoin
? IDE ¨C Visual Studio Code
? Dapp browsers¨C MetaMask
? Smart Contract Language - Solidity
? Simulator - ganache
? Library ¨C Web3.js
? Ethereum development framework ¨C Truffle
? Module bundler ¨C Webpack
MetaCoin
? Initial project
? Writing smart contract
? Testing smart contract
? Deploy smart contract
? Interacting with smart contract
installation
1. Install Truffle globally.
> npm install ¨Cg truffle
2. Initial truffle project
> truffle init
3. Run the Ganache.
1. setup port -8545
Truffle project folder
? contracts/: Directory for Solidity contracts
? migrations/: Directory for scriptable deployment files
? test/: Directory for test files for testing your application and
contracts
? Truffle-config.js: Truffle configuration file
MetaCoin
Deployment & Test
4. Compile and migrate the smart contracts.
> truffle compile
> truffle migrate
5. To run all test , simply run
> truffle test
Deploy smart contract
Ethereum Blockchain
Ethereu
Node
Interact by transaction
Deploy smart contract
Solidity compiler: solc
Contracts bytecode
and ABI
Development
Source code: *.sol
installation
6. Run the lite server for front-end hot
reloading (outside the development
console). Smart contract changes must be
manually recompiled and migrated.
> npm run dev
Initial application
getBalance() Ethereum
Blockchain
Call balanceOf
Return value
Connect Wallet
? Get Wallet address
Account-Balance
? Get ether Balance
? Get MetaCoin Balance
transfer
handleTransfer() Ethereum
Blockchain
transfer
Return TXID
transfer
Web3.js
? Deploy smart contract
? Transaction Object
? Reflection
? Application Binary Interface (ABI)
? Contract Functions
? Call
? Transaction
Check MetaCoin Balance
Check MetaCoin
Detecting account Change and
network change
detecting account & network
Ethereum network
Network Network ID Type
mainnet 1 Production
Goerli 5 Test
Kovan 42 Test
Goerli network
Deployed smart contract
? Remix
? Address : 0x09F9772D81815D2FF0eD4A6A58F53f26039166f3
? Etherscan :
https://goerli.etherscan.io/address/0x09F9772D81815D2FF0eD4A6A5
8F53f26039166f3
ERC20
ERC20
? ERC ¨C Ethereum Request for Comment
? the most widespread token standard for fungible assets, albeit
somewhat limited by its simplicity.
? ERC20 has 3 info, 6 functions and 2 events¡£
? https://theethereum.wiki/w/index.php/ERC20_Token_Standard
ERC20 - information
? Name: the name of the token.
? Symbol: the symbol of the token. https://etherscan.io/
? Decimals: the number of decimals the token uses ¨C
? e.g. 8, means to divide the token amount by 100000000 to get its
user representation.
ERC20 - Functions
? totalSupply(): the total token supply.
? balanceOf(address _owner): the account balance of another
account with address _owner
? Transfer(address _to, uint256 _value):Transfers _value amount of
tokens to address _to, and MUST fire the Transfer event.
? transferFrom(address _from, address _to, uint256 _value):
_value amount of tokens from address _from to address _to, and
MUST fire the Transfer event.
ERC20 - Functions
? Approve (address _spender, uint256 _value): Allows _spender to
withdraw from your account multiple times, up to
the _value amount.
? Allowance(address _owner, address _spender): the amount
which _spender is still allowed to withdraw from _owner.
ERC20 - Event
? Transfer(address indexed _from, address indexed _to, uint256 _value):
MUST trigger when tokens are transferred, including zero value
transfers.
? Approval(address indexed _owner, addressindexed _spender, uint256
_value): MUST trigger on any successful call to approve.
Q & A

More Related Content

20221110 MetaCoin

  • 2. Kenneth Hu ? I am a software developer , not trader. ? I am enthusiast, not expert. ? Ethereum, Bitcoin ? Email: Kenneth.hu@Hotmail.com ? Linkedin https://www.linkedin.com/in/hukenneth/ ? Blockchain&Dapps meetup ? DeFi - Decentralized Finance, SG
  • 3. Agenda ? 1. Introduction ? 2. Development software tools and environment ? 3. Create crypto currency ? 4. Create the user interface ? 5. Connect to wallet ? 6. Send crypto currency ? 7. Confirm receipt of virtual currency ? 8. ERC20
  • 6. MetaCoin ? IDE ¨C Visual Studio Code ? Dapp browsers¨C MetaMask ? Smart Contract Language - Solidity ? Simulator - ganache ? Library ¨C Web3.js ? Ethereum development framework ¨C Truffle ? Module bundler ¨C Webpack
  • 7. MetaCoin ? Initial project ? Writing smart contract ? Testing smart contract ? Deploy smart contract ? Interacting with smart contract
  • 8. installation 1. Install Truffle globally. > npm install ¨Cg truffle 2. Initial truffle project > truffle init 3. Run the Ganache. 1. setup port -8545
  • 9. Truffle project folder ? contracts/: Directory for Solidity contracts ? migrations/: Directory for scriptable deployment files ? test/: Directory for test files for testing your application and contracts ? Truffle-config.js: Truffle configuration file
  • 11. Deployment & Test 4. Compile and migrate the smart contracts. > truffle compile > truffle migrate 5. To run all test , simply run > truffle test
  • 12. Deploy smart contract Ethereum Blockchain Ethereu Node Interact by transaction Deploy smart contract Solidity compiler: solc Contracts bytecode and ABI Development Source code: *.sol
  • 13. installation 6. Run the lite server for front-end hot reloading (outside the development console). Smart contract changes must be manually recompiled and migrated. > npm run dev
  • 15. Connect Wallet ? Get Wallet address
  • 16. Account-Balance ? Get ether Balance ? Get MetaCoin Balance
  • 19. Web3.js ? Deploy smart contract ? Transaction Object ? Reflection ? Application Binary Interface (ABI) ? Contract Functions ? Call ? Transaction
  • 22. Detecting account Change and network change
  • 24. Ethereum network Network Network ID Type mainnet 1 Production Goerli 5 Test Kovan 42 Test
  • 26. Deployed smart contract ? Remix ? Address : 0x09F9772D81815D2FF0eD4A6A58F53f26039166f3 ? Etherscan : https://goerli.etherscan.io/address/0x09F9772D81815D2FF0eD4A6A5 8F53f26039166f3
  • 27. ERC20
  • 28. ERC20 ? ERC ¨C Ethereum Request for Comment ? the most widespread token standard for fungible assets, albeit somewhat limited by its simplicity. ? ERC20 has 3 info, 6 functions and 2 events¡£ ? https://theethereum.wiki/w/index.php/ERC20_Token_Standard
  • 29. ERC20 - information ? Name: the name of the token. ? Symbol: the symbol of the token. https://etherscan.io/ ? Decimals: the number of decimals the token uses ¨C ? e.g. 8, means to divide the token amount by 100000000 to get its user representation.
  • 30. ERC20 - Functions ? totalSupply(): the total token supply. ? balanceOf(address _owner): the account balance of another account with address _owner ? Transfer(address _to, uint256 _value):Transfers _value amount of tokens to address _to, and MUST fire the Transfer event. ? transferFrom(address _from, address _to, uint256 _value): _value amount of tokens from address _from to address _to, and MUST fire the Transfer event.
  • 31. ERC20 - Functions ? Approve (address _spender, uint256 _value): Allows _spender to withdraw from your account multiple times, up to the _value amount. ? Allowance(address _owner, address _spender): the amount which _spender is still allowed to withdraw from _owner.
  • 32. ERC20 - Event ? Transfer(address indexed _from, address indexed _to, uint256 _value): MUST trigger when tokens are transferred, including zero value transfers. ? Approval(address indexed _owner, addressindexed _spender, uint256 _value): MUST trigger on any successful call to approve.
  • 33. Q & A