Skip to content

effy-coding/ethereum-bank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

μ†Œκ°œ

Ethereum_Truffle

이 ν”„λ‘œμ νŠΈμ— λŒ€ν•œ μžμ„Έν•œ λ¬Έμ„œλŠ” μ—¬κΈ°μ—μ„œ ν™•μΈν•˜μ„Έμš”.

Truffle 을 μ΄μš©ν•œ μž…μΆœκΈˆ κ°€λŠ₯ν•œ 이더리움 μ€ν–‰μž…λ‹ˆλ‹€.

μ€€λΉ„λ¬Ό

  • Node.js
  • Truffle
  • Ganache

μ‚¬μš©λ²•

λ¨Όμ € Ganache λ₯Ό 7545 ν¬νŠΈμ— κ°€λ™μ‹œν‚΅λ‹ˆλ‹€.

μš°λ¦¬λŠ” ν”„λ‘ νŠΈμ—”λ“œ 없이 μ½˜μ†” ν™˜κ²½ μ‹€μŠ΅ν•©λ‹ˆλ‹€.

> truffle console
truffle(development)>

이제 Deploy ν•œ Contract 의 μΈμŠ€ν„΄μŠ€λ₯Ό λ³€μˆ˜μ— μ €μž₯ν•©λ‹ˆλ‹€:

truffle(development)> Bank.deployed().then(instance => bank = instance)

Bank.deployed() λŠ” Contract 의 μΈμŠ€ν„΄μŠ€ ν‰κ°€ν•˜λŠ” ν”„λ‘œλ―ΈμŠ€(Promise)λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€. then 을 μ΄μš©ν•˜μ—¬ μš°λ¦¬λŠ” 이λ₯Ό bank 에 bind ν•©λ‹ˆλ‹€.

owner 멀버 λ³€μˆ˜λ₯Ό ν™•μΈν•΄λ΄…μ‹œλ‹€:

> bank.owner()
'0xdaf72fcee99c3ed561b5f91a83b69c6f3d6b02e8'

Ganache 의 첫 번째 계정과 address κ°€ λ™μΌν•©λ‹ˆλ‹€!

이제 은행에 10 ETH 만큼 μž…κΈˆμ„ ν•΄λ΄…μ‹œλ‹€:

> bank.deposit({value: web3.toWei(10, 'ether')})

deposit 은 payable ν•¨μˆ˜μž…λ‹ˆλ‹€. λ•Œλ¬Έμ— μ €ν¬λŠ” value λ₯Ό 맀개 λ³€μˆ˜λ‘œ 담을 수 μžˆμŠ΅λ‹ˆλ‹€. value λŠ” ETH 의 μ΅œμ†Œ λ‹¨μœ„μΈ Wei λ₯Ό κ°€μ§‘λ‹ˆλ‹€. λ”°λΌμ„œ web3.toWei λ₯Ό 톡해 10 ETH λ₯Ό Wei 둜 λ³€ν™˜ν•΄μ•Όν•©λ‹ˆλ‹€.

이제 Ganache 의 첫 번째 κ³„μ •μ˜ μž”μ•‘(balance)을 ν™•μΈν•©λ‹ˆλ‹€:

Ganache_First_Account

89.94 ETH κ°€ λ‚¨μ•˜μŠ΅λ‹ˆλ‹€. μ™œ 90.00 ETH κ°€ μ•„λ‹κΉŒμš”? μ΄λŠ” Contract 의 ν•¨μˆ˜λ₯Ό μ‹€ν–‰μ‹œν‚€λŠ” 수수료(Gas) λ•Œλ¬Έμž…λ‹ˆλ‹€. Gas 에 λŒ€ν•œ μžμ„Έν•œ λ‚΄μš©μ€ μ—¬κΈ°λ₯Ό μ°Έκ³ ν•˜μ„Έμš”.

이제 μΆœκΈˆν•  μ°¨λ‘€μž…λ‹ˆλ‹€:

> bank.withdraw()

Ganache_First_Account

첫 번째 계정에 10 ETH κ°€ λ‹€μ‹œ λ“€μ–΄μ™”μŠ΅λ‹ˆλ‹€!

더 읽어보기

About

πŸ’΅ Simple ethereum bank with Truffle

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published