Ver3.0 ๐ ํ์ด์ฌ๊ณผ ํ๋ผ์คํฌ๋ก ๋ธ๋ก์ฒด์ธ ์ง๊ฐ ์ฐ๋ ์น์ฌ์ดํธ ๋ง๋ค๊ธฐ: ์ค์ ๊ฐ๋ฐ ๊ฐ์ด๋

๐ ํ์ด์ฌ๊ณผ ํ๋ผ์คํฌ๋ก ๋ธ๋ก์ฒด์ธ ์ง๊ฐ ์ฐ๋ ์น์ฌ์ดํธ ๋ง๋ค๊ธฐ: ์ค์ ๊ฐ๋ฐ ๊ฐ์ด๋
๐ ์๋
! ์ค๋์ ์ ๋ง ํฅ๋ฏธ์ง์งํ ์ฃผ์ ๋ฅผ ๊ฐ์ง๊ณ ์์ด. ๋ฐ๋ก ํ์ด์ฌ๊ณผ ํ๋ผ์คํฌ๋ฅผ ํ์ฉํ ๋ธ๋ก์ฒด์ธ ์ง๊ฐ ์ฐ๋ ์น์ฌ์ดํธ ๊ฐ๋ฐ์ด์ผ. ์์ฆ NFT, ๋ํ์ด(DeFi), Web3๊ฐ ๋์ธ์์? ์ด๋ฐ ์๋น์ค๋ค์ ๋ง๋ค๋ ค๋ฉด ํ์์ ์ผ๋ก ์ฌ์ฉ์์ ์ํธํํ ์ง๊ฐ์ ์น์ฌ์ดํธ์ ์ฐ๊ฒฐํด์ผ ํด.
์ฒ์ ๋ค์ผ๋ฉด ์์ฒญ ์ด๋ ค์ ๋ณด์ด์ง? ํ์ง๋ง ๊ฑฑ์ ๋ง! ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผ์ค๋ฉด ๋๊ตฌ๋ ๋ง๋ค ์ ์์ด. ์ด ๊ธ์ ๋ค ์ฝ๊ณ ๋๋ฉด ๋ฉํ๋ง์คํฌ ๊ฐ์ ์ง๊ฐ์ ์น์ฌ์ดํธ์ ์ฐ๋ํ๊ณ , ๋ธ๋ก์ฒด์ธ๊ณผ ํต์ ํ๋ ์น ์ ํ๋ฆฌ์ผ์ด์
์ ์ง์ ๋ง๋ค ์ ์์ ๊ฑฐ์ผ. ๐ช
๐ฏ ์ ๋ธ๋ก์ฒด์ธ ์ง๊ฐ ์ฐ๋์ด ํ์ํ ๊น?
๋ณธ๊ฒฉ์ ์ผ๋ก ๊ฐ๋ฐ์ ๋ค์ด๊ฐ๊ธฐ ์ ์, ์ ์ด๊ฒ ์ค์ํ์ง๋ถํฐ ์ด์ผ๊ธฐํด๋ณด์. ์ ํต์ ์ธ ์น์ฌ์ดํธ๋ ์ด๋ฉ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๋ก ๋ก๊ทธ์ธํ์ง? ํ์ง๋ง Web3 ์ธ๊ณ์์๋ ์ง๊ฐ ์ฃผ์๊ฐ ๊ณง ๋น์ ์ ์ ์์ด์ผ.
๋ธ๋ก์ฒด์ธ ์ง๊ฐ ์ฐ๋์ ํตํด ์ฐ๋ฆฌ๊ฐ ํ ์ ์๋ ๊ฒ๋ค์ ์ ๋ง ๋ค์ํด:
๐ ํ์ค์ํ ์ธ์ฆ
๋ณ๋์ ํ์๊ฐ์
์์ด ์ง๊ฐ ์ฃผ์๋ก ์ฌ์ฉ์๋ฅผ ์๋ณํ ์ ์์ด. ๋น๋ฐ๋ฒํธ๋ฅผ ๊ด๋ฆฌํ ํ์๋ ์๊ณ , ๊ฐ์ธ์ ๋ณด ์ ์ถ ๊ฑฑ์ ๋ ์ค์ด๋ค์ง.
๐ฐ ์ํธํํ ๊ฑฐ๋
์ฌ์ฉ์๊ฐ ์ง์ ํ ํฐ์ ์ ์กํ๊ฑฐ๋ ๋ฐ์ ์ ์์ด. NFT ๋ง์ผํ๋ ์ด์ค๋ ๋ํ์ด ์๋น์ค์ ํต์ฌ ๊ธฐ๋ฅ์ด์ผ.
๐ ์ค๋งํธ ์ปจํธ๋ํธ ์คํ
๋ธ๋ก์ฒด์ธ ์์ ์ค๋งํธ ์ปจํธ๋ํธ์ ์ํธ์์ฉํ ์ ์์ด. ํฌํ, ๊ฑฐ๋ฒ๋์ค, ์๋ํ๋ ๊ธ์ต ์๋น์ค ๋ฑ์ ๊ตฌํํ ์ ์์ง.
๐จ NFT ๊ด๋ฆฌ
์ฌ์ฉ์๊ฐ ๋ณด์ ํ NFT๋ฅผ ์กฐํํ๊ณ , ๋ฏผํ
ํ๊ณ , ๊ฑฐ๋ํ ์ ์๋ ํ๋ซํผ์ ๋ง๋ค ์ ์์ด.
์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์๋ ๋ธ๋ก์ฒด์ธ ๊ธฐ์ ์ ํ์ฉํ ์ฌ๋ฅ ๊ฑฐ๋ ์์คํ ์ ๊ตฌ์ถํ๋ค๋ฉด, ๋ ํฌ๋ช ํ๊ณ ์ ๋ขฐํ ์ ์๋ ๊ฑฐ๋ ํ๊ฒฝ์ ๋ง๋ค ์ ์์ ๊ฑฐ์ผ. โจ
๐ ๏ธ ๊ฐ๋ฐ ํ๊ฒฝ ์ค๋นํ๊ธฐ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ๊ฐ๋ฐ์ ์์ํด๋ณผ๊น? ๋จผ์ ํ์ํ ๋๊ตฌ๋ค์ ์ค๋นํด์ผ ํด. ๊ฑฑ์ ํ์ง ๋ง, ํ๋ํ๋ ์ฐจ๊ทผ์ฐจ๊ทผ ์ค๋ช ํด์ค๊ฒ!
๐ฆ ํ์ ์ค์น ํญ๋ชฉ
1. Python 3.8 ์ด์
ํ์ด์ฌ์ด ์๋ค๋ฉด python.org์์ ๋ค์ด๋ก๋๋ฐ์. ์ต์ ๋ฒ์ ์ ๊ถ์ฅํด!
2. Flask ํ๋ ์์ํฌ
ํ์ด์ฌ์ ๊ฒฝ๋ ์น ํ๋ ์์ํฌ์ผ. ๋น ๋ฅด๊ณ ๊ฐ๋จํ๊ฒ ์น ์ ํ๋ฆฌ์ผ์ด์
์ ๋ง๋ค ์ ์์ด.
3. Web3.py ๋ผ์ด๋ธ๋ฌ๋ฆฌ
ํ์ด์ฌ์์ ์ด๋๋ฆฌ์ ๋ธ๋ก์ฒด์ธ๊ณผ ํต์ ํ๊ธฐ ์ํ ํ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ผ.
4. MetaMask ๋ธ๋ผ์ฐ์ ํ์ฅ ํ๋ก๊ทธ๋จ
ํ
์คํธ๋ฅผ ์ํด ํฌ๋กฌ์ด๋ ํ์ด์ดํญ์ค์ ๋ฉํ๋ง์คํฌ๋ฅผ ์ค์นํ์.
๐ป ๊ฐ์ํ๊ฒฝ ์ค์ ๋ฐ ํจํค์ง ์ค์น
ํ๋ก์ ํธ๋ฅผ ์์ํ๊ธฐ ์ ์ ๊ฐ์ํ๊ฒฝ์ ๋ง๋๋ ๊ฒ ์ข์. ๋ค๋ฅธ ํ๋ก์ ํธ์ ํจํค์ง ์ถฉ๋์ ๋ฐฉ์งํ ์ ์๊ฑฐ๋ . ํฐ๋ฏธ๋์ ์ด๊ณ ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํด๋ด:
# ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ ์์ฑ
mkdir blockchain-wallet-app
cd blockchain-wallet-app
# ๊ฐ์ํ๊ฒฝ ์์ฑ
python -m venv venv
# ๊ฐ์ํ๊ฒฝ ํ์ฑํ (Windows)
venv\Scripts\activate
# ๊ฐ์ํ๊ฒฝ ํ์ฑํ (Mac/Linux)
source venv/bin/activate
# ํ์ํ ํจํค์ง ์ค์น
pip install flask
pip install web3
pip install python-dotenv
pip install flask-cors
๐ก Pro Tip: requirements.txt ํ์ผ์ ๋ง๋ค์ด์ ํจํค์ง ๋ฒ์ ์ ๊ด๋ฆฌํ๋ฉด ๋์ค์ ๋ฐฐํฌํ ๋ ํจ์ฌ ํธํด! ๋ค์ ๋ช
๋ น์ด๋ก ํ์ฌ ์ค์น๋ ํจํค์ง ๋ชฉ๋ก์ ์ ์ฅํ ์ ์์ด:
pip freeze > requirements.txt
๐๏ธ ํ๋ก์ ํธ ๊ตฌ์กฐ ์ค๊ณํ๊ธฐ
์ฝ๋๋ฅผ ์์ฑํ๊ธฐ ์ ์ ํ๋ก์ ํธ ๊ตฌ์กฐ๋ฅผ ์ ์ค๊ณํ๋ ๊ฒ ์ค์ํด. ๋์ค์ ์ ์ง๋ณด์ํ๊ธฐ๋ ์ฝ๊ณ , ๊ธฐ๋ฅ์ ์ถ๊ฐํ ๋๋ ํจ์ฌ ํธํ๊ฑฐ๋ . ์ฐ๋ฆฌ๊ฐ ๋ง๋ค ํ๋ก์ ํธ์ ๊ตฌ์กฐ๋ ์ด๋ ๊ฒ ๋ ๊ฑฐ์ผ:
blockchain-wallet-app/
โ
โโโ venv/ # ๊ฐ์ํ๊ฒฝ (git์๋ ์ฌ๋ฆฌ์ง ์์)
โโโ static/ # ์ ์ ํ์ผ๋ค
โ โโโ css/
โ โ โโโ style.css # ์คํ์ผ์ํธ
โ โโโ js/
โ โโโ wallet.js # ์ง๊ฐ ์ฐ๋ JavaScript
โ
โโโ templates/ # HTML ํ
ํ๋ฆฟ
โ โโโ index.html # ๋ฉ์ธ ํ์ด์ง
โ โโโ dashboard.html # ๋์๋ณด๋ ํ์ด์ง
โ
โโโ app.py # Flask ๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
โโโ blockchain.py # ๋ธ๋ก์ฒด์ธ ๊ด๋ จ ํจ์๋ค
โโโ config.py # ์ค์ ํ์ผ
โโโ .env # ํ๊ฒฝ ๋ณ์ (git์๋ ์ฌ๋ฆฌ์ง ์์)
โโโ requirements.txt # ํจํค์ง ์์กด์ฑ
โโโ README.md # ํ๋ก์ ํธ ์ค๋ช
์ด ๊ตฌ์กฐ๋ ๊ด์ฌ์ฌ์ ๋ถ๋ฆฌ(Separation of Concerns) ์์น์ ๋ฐ๋ฅด๊ณ ์์ด. ๊ฐ ํ์ผ์ด ๋ช ํํ ์ญํ ์ ๊ฐ์ง๊ณ ์์ด์ ๋์ค์ ์ด๋๋ฅผ ์์ ํด์ผ ํ ์ง ๊ธ๋ฐฉ ์ ์ ์์ง. ๐ฏ
โ๏ธ Flask ๋ฐฑ์๋ ๊ตฌ์ถํ๊ธฐ
์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ์ฝ๋๋ฅผ ์์ฑํด๋ณด์! ๋จผ์ Flask ๋ฐฑ์๋๋ถํฐ ๋ง๋ค ๊ฑฐ์ผ. app.py ํ์ผ์ ์์ฑํ๊ณ ๋ค์ ์ฝ๋๋ฅผ ์ ๋ ฅํด๋ด:
๐ ๊ธฐ๋ณธ Flask ์ ํ๋ฆฌ์ผ์ด์ ์ค์
from flask import Flask, render_template, jsonify, request
from flask_cors import CORS
from web3 import Web3
import os
from dotenv import load_dotenv
# ํ๊ฒฝ ๋ณ์ ๋ก๋
load_dotenv()
app = Flask(__name__)
CORS(app) # CORS ์ค์ (ํ๋ก ํธ์๋์ ํต์ ์ ์ํด)
# Web3 ์ธ์คํด์ค ์์ฑ
# Infura๋ Alchemy ๊ฐ์ ๋
ธ๋ ํ๋ก๋ฐ์ด๋ ์ฌ์ฉ
INFURA_URL = os.getenv('INFURA_URL')
w3 = Web3(Web3.HTTPProvider(INFURA_URL))
# ๋ธ๋ก์ฒด์ธ ์ฐ๊ฒฐ ํ์ธ
if w3.is_connected():
print("โ
๋ธ๋ก์ฒด์ธ ๋คํธ์ํฌ์ ์ฑ๊ณต์ ์ผ๋ก ์ฐ๊ฒฐ๋์์ต๋๋ค!")
else:
print("โ ๋ธ๋ก์ฒด์ธ ์ฐ๊ฒฐ ์คํจ")
@app.route('/')
def index():
"""๋ฉ์ธ ํ์ด์ง"""
return render_template('index.html')
@app.route('/api/network-info')
def network_info():
"""๋คํธ์ํฌ ์ ๋ณด ๋ฐํ"""
try:
chain_id = w3.eth.chain_id
block_number = w3.eth.block_number
gas_price = w3.eth.gas_price
return jsonify({
'success': True,
'chain_id': chain_id,
'block_number': block_number,
'gas_price': w3.from_wei(gas_price, 'gwei')
})
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
@app.route('/api/balance/<address>')
def get_balance(address):
"""์ง๊ฐ ์ฃผ์์ ์์ก ์กฐํ"""
try:
# ์ฃผ์ ์ ํจ์ฑ ๊ฒ์ฌ
if not w3.is_address(address):
return jsonify({
'success': False,
'error': '์ ํจํ์ง ์์ ์ฃผ์์
๋๋ค'
}), 400
# ์ฒดํฌ์ฌ ์ฃผ์๋ก ๋ณํ
checksum_address = w3.to_checksum_address(address)
# ์์ก ์กฐํ (Wei ๋จ์)
balance_wei = w3.eth.get_balance(checksum_address)
# ETH ๋จ์๋ก ๋ณํ
balance_eth = w3.from_wei(balance_wei, 'ether')
return jsonify({
'success': True,
'address': checksum_address,
'balance_wei': str(balance_wei),
'balance_eth': str(balance_eth)
})
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
if __name__ == '__main__':
app.run(debug=True, port=5000)
๐ ํ๊ฒฝ ๋ณ์ ์ค์ ํ๊ธฐ
.env ํ์ผ์ ๋ง๋ค์ด์ ๋ฏผ๊ฐํ ์ ๋ณด๋ฅผ ์ ์ฅํ์. ์ด ํ์ผ์ ์ ๋ git์ ์ฌ๋ฆฌ๋ฉด ์ ๋ผ!
INFURA_URL=https://mainnet.infura.io/v3/YOUR_PROJECT_IDInfura๋ Alchemy์์ ๋ฌด๋ฃ ๊ณ์ ์ ๋ง๋ค๋ฉด ํ๋ก์ ํธ ID๋ฅผ ๋ฐ์ ์ ์์ด. ์ด๊ฑธ ์ฌ์ฉํ๋ฉด ์์ฒด ๋ ธ๋๋ฅผ ์ด์ํ์ง ์์๋ ๋ธ๋ก์ฒด์ธ๊ณผ ํต์ ํ ์ ์์ง!
๐ ์ง๊ฐ ์๋ช ๊ฒ์ฆ ๊ธฐ๋ฅ ์ถ๊ฐ
์ฌ์ฉ์๊ฐ ์ ๋ง ํด๋น ์ง๊ฐ์ ์์ ์์ธ์ง ํ์ธํ๋ ค๋ฉด ์๋ช ๊ฒ์ฆ์ด ํ์ํด. blockchain.py ํ์ผ์ ๋ง๋ค์ด์ ๊ด๋ จ ํจ์๋ค์ ์ถ๊ฐํด๋ณด์:
from web3 import Web3
from eth_account.messages import encode_defunct
import secrets
def generate_nonce():
"""๋๋ค nonce ์์ฑ"""
return secrets.token_hex(16)
def verify_signature(address, message, signature):
"""
์ง๊ฐ ์๋ช
๊ฒ์ฆ
Args:
address: ์ง๊ฐ ์ฃผ์
message: ์๋ช
ํ ๋ฉ์์ง
signature: ์๋ช
๊ฐ
Returns:
bool: ๊ฒ์ฆ ์ฑ๊ณต ์ฌ๋ถ
"""
try:
w3 = Web3()
# ๋ฉ์์ง ์ธ์ฝ๋ฉ
message_hash = encode_defunct(text=message)
# ์๋ช
์ผ๋ก๋ถํฐ ์ฃผ์ ๋ณต๊ตฌ
recovered_address = w3.eth.account.recover_message(
message_hash,
signature=signature
)
# ์ฃผ์ ๋น๊ต (๋์๋ฌธ์ ๊ตฌ๋ถ ์์ด)
return recovered_address.lower() == address.lower()
except Exception as e:
print(f"์๋ช
๊ฒ์ฆ ์ค๋ฅ: {e}")
return False
def get_transaction_receipt(tx_hash):
"""ํธ๋์ญ์
์์์ฆ ์กฐํ"""
try:
w3 = Web3(Web3.HTTPProvider(os.getenv('INFURA_URL')))
receipt = w3.eth.get_transaction_receipt(tx_hash)
return {
'success': True,
'status': receipt['status'],
'block_number': receipt['blockNumber'],
'gas_used': receipt['gasUsed'],
'from': receipt['from'],
'to': receipt['to']
}
except Exception as e:
return {
'success': False,
'error': str(e)
}
์ด์ app.py์ ์๋ช ๊ฒ์ฆ ์๋ํฌ์ธํธ๋ฅผ ์ถ๊ฐํ์:
from blockchain import generate_nonce, verify_signature
# ์ธ์
๊ด๋ฆฌ๋ฅผ ์ํ ๋์
๋๋ฆฌ (์ค์ ํ๋ก๋์
์์๋ Redis ๋ฑ ์ฌ์ฉ)
nonce_storage = {}
@app.route('/api/request-nonce/<address>')
def request_nonce(address):
"""๋ก๊ทธ์ธ์ ์ํ nonce ์์ฒญ"""
try:
if not w3.is_address(address):
return jsonify({
'success': False,
'error': '์ ํจํ์ง ์์ ์ฃผ์์
๋๋ค'
}), 400
checksum_address = w3.to_checksum_address(address)
nonce = generate_nonce()
# nonce ์ ์ฅ (์ค์ ๋ก๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ Redis ์ฌ์ฉ)
nonce_storage[checksum_address] = nonce
return jsonify({
'success': True,
'nonce': nonce,
'message': f'๋ธ๋ก์ฒด์ธ ์ง๊ฐ ๋ก๊ทธ์ธ\n\nNonce: {nonce}\n\n์ด ์๋ช
์ ๋น์ ์ ์ ์์ ํ์ธํ๊ธฐ ์ํ ๊ฒ์
๋๋ค.'
})
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
@app.route('/api/verify-signature', methods=['POST'])
def verify_wallet_signature():
"""์ง๊ฐ ์๋ช
๊ฒ์ฆ"""
try:
data = request.json
address = data.get('address')
signature = data.get('signature')
if not address or not signature:
return jsonify({
'success': False,
'error': '์ฃผ์์ ์๋ช
์ด ํ์ํฉ๋๋ค'
}), 400
checksum_address = w3.to_checksum_address(address)
# ์ ์ฅ๋ nonce ๊ฐ์ ธ์ค๊ธฐ
nonce = nonce_storage.get(checksum_address)
if not nonce:
return jsonify({
'success': False,
'error': 'nonce๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค'
}), 400
# ๋ฉ์์ง ์ฌ๊ตฌ์ฑ
message = f'๋ธ๋ก์ฒด์ธ ์ง๊ฐ ๋ก๊ทธ์ธ\n\nNonce: {nonce}\n\n์ด ์๋ช
์ ๋น์ ์ ์ ์์ ํ์ธํ๊ธฐ ์ํ ๊ฒ์
๋๋ค.'
# ์๋ช
๊ฒ์ฆ
is_valid = verify_signature(checksum_address, message, signature)
if is_valid:
# ์ฌ์ฉ๋ nonce ์ญ์
del nonce_storage[checksum_address]
# ์ค์ ๋ก๋ ์ฌ๊ธฐ์ JWT ํ ํฐ ์์ฑ ๋ฑ์ ์์
์ํ
return jsonify({
'success': True,
'message': '์ธ์ฆ ์ฑ๊ณต',
'address': checksum_address
})
else:
return jsonify({
'success': False,
'error': '์๋ช
๊ฒ์ฆ ์คํจ'
}), 401
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
โ ๏ธ ๋ณด์ ์ฃผ์์ฌํญ
์ ์ฝ๋์ nonce_storage๋ ์์ ๋ฅผ ์ํ ๊ฐ๋จํ ๊ตฌํ์ด์ผ. ์ค์ ํ๋ก๋์
ํ๊ฒฝ์์๋ ๋ค์์ ๊ณ ๋ คํด์ผ ํด:
โข Redis๋ Memcached ๊ฐ์ ์ธ๋ฉ๋ชจ๋ฆฌ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฌ์ฉ
โข nonce์ ๋ง๋ฃ ์๊ฐ ์ค์ (๋ณดํต 5-10๋ถ)
โข ์ฌ์ฉ๋ nonce๋ ์ฆ์ ์ญ์ ํ์ฌ ์ฌ์ฌ์ฉ ๋ฐฉ์ง
โข HTTPS ์ฌ์ฉ ํ์
โข Rate limiting ์ ์ฉํ์ฌ ๋ฌด์ฐจ๋ณ ๋์
๊ณต๊ฒฉ ๋ฐฉ์ง
๐จ ํ๋ก ํธ์๋ ๊ฐ๋ฐ: ์ง๊ฐ ์ฐ๋ UI
๋ฐฑ์๋๊ฐ ์ค๋น๋์์ผ๋ ์ด์ ์ฌ์ฉ์๊ฐ ์ค์ ๋ก ๋ณด๊ณ ์ํธ์์ฉํ ํ๋ก ํธ์๋๋ฅผ ๋ง๋ค์ด๋ณด์! ๋จผ์ HTML ํ ํ๋ฆฟ๋ถํฐ ์์ํ ๊ฒ.
๐ index.html ์์ฑ
templates/index.html ํ์ผ์ ๋ง๋ค๊ณ ๋ค์ ์ฝ๋๋ฅผ ์ ๋ ฅํด๋ด:
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>๋ธ๋ก์ฒด์ธ ์ง๊ฐ ์ฐ๋ ๋ฐ๋ชจ</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<div class="container">
<header>
<h1>๐ Web3 ์ง๊ฐ ์ฐ๋ ๋ฐ๋ชจ</h1>
<p>MetaMask๋ฅผ ์ฐ๊ฒฐํ์ฌ ๋ธ๋ก์ฒด์ธ๊ณผ ์ํธ์์ฉํด๋ณด์ธ์</p>
</header>
<div id="wallet-section">
<div id="connect-section">
<button id="connectButton" class="btn-primary">
๐ฆ MetaMask ์ฐ๊ฒฐํ๊ธฐ
</button>
</div>
<div id="wallet-info" style="display: none;">
<div class="info-card">
<h3>๐ผ ์ฐ๊ฒฐ๋ ์ง๊ฐ ์ ๋ณด</h3>
<div class="info-item">
<span class="label">์ฃผ์:</span>
<span id="walletAddress" class="value"></span>
</div>
<div class="info-item">
<span class="label">์์ก:</span>
<span id="walletBalance" class="value"></span>
</div>
<div class="info-item">
<span class="label">๋คํธ์ํฌ:</span>
<span id="networkName" class="value"></span>
</div>
</div>
<div class="action-buttons">
<button id="signButton" class="btn-secondary">
โ๏ธ ๋ฉ์์ง ์๋ช
ํ๊ธฐ
</button>
<button id="disconnectButton" class="btn-danger">
๐ ์ฐ๊ฒฐ ํด์
</button>
</div>
</div>
</div>
<div id="network-info" class="info-card">
<h3>๐ ๋คํธ์ํฌ ์ ๋ณด</h3>
<div id="networkData">๋ก๋ฉ ์ค...</div>
</div>
<div id="status-message" class="status-message"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="{{ url_for('static', filename='js/wallet.js') }}"></script>
</body>
</html>
๐จ CSS ์คํ์ผ๋ง
static/css/style.css ํ์ผ์ ๋ง๋ค์ด์ ์์๊ฒ ๊พธ๋ฉฐ๋ณด์:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
border-radius: 20px;
padding: 40px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
header {
text-align: center;
margin-bottom: 40px;
}
header h1 {
color: #667eea;
font-size: 2.5em;
margin-bottom: 10px;
}
header p {
color: #666;
font-size: 1.1em;
}
.btn-primary, .btn-secondary, .btn-danger {
padding: 15px 30px;
font-size: 1.1em;
border: none;
border-radius: 10px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 600;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}
.btn-secondary {
background: #10b981;
color: white;
margin-right: 10px;
}
.btn-danger {
background: #ef4444;
color: white;
}
#connect-section {
text-align: center;
padding: 60px 20px;
}
.info-card {
background: #f8f9fa;
border-radius: 15px;
padding: 25px;
margin: 20px 0;
}
.info-card h3 {
color: #333;
margin-bottom: 20px;
font-size: 1.5em;
}
.info-item {
display: flex;
justify-content: space-between;
padding: 12px 0;
border-bottom: 1px solid #e5e7eb;
}
.info-item:last-child {
border-bottom: none;
}
.label {
font-weight: 600;
color: #666;
}
.value {
color: #333;
font-family: monospace;
}
.action-buttons {
display: flex;
justify-content: center;
margin-top: 30px;
}
.status-message {
margin-top: 20px;
padding: 15px;
border-radius: 10px;
text-align: center;
font-weight: 600;
display: none;
}
.status-message.success {
background: #d1fae5;
color: #065f46;
display: block;
}
.status-message.error {
background: #fee2e2;
color: #991b1b;
display: block;
}
@media (max-width: 768px) {
.container {
padding: 20px;
}
header h1 {
font-size: 1.8em;
}
.action-buttons {
flex-direction: column;
}
.btn-secondary {
margin-right: 0;
margin-bottom: 10px;
}
}
โก JavaScript๋ก ์ง๊ฐ ์ฐ๋ ๊ตฌํ
์ด์ ๊ฐ์ฅ ์ค์ํ ๋ถ๋ถ์ด์ผ! static/js/wallet.js ํ์ผ์ ๋ง๋ค์ด์ ์ค์ ์ง๊ฐ ์ฐ๋ ๋ก์ง์ ๊ตฌํํด๋ณด์:
// ์ ์ญ ๋ณ์
let web3;
let currentAccount;
// ํ์ด์ง ๋ก๋ ์ ์คํ
window.addEventListener('load', async () => {
// MetaMask ์ค์น ํ์ธ
if (typeof window.ethereum !== 'undefined') {
console.log('โ
MetaMask๊ฐ ์ค์น๋์ด ์์ต๋๋ค!');
web3 = new Web3(window.ethereum);
// ์ด๋ฏธ ์ฐ๊ฒฐ๋ ๊ณ์ ์ด ์๋์ง ํ์ธ
const accounts = await web3.eth.getAccounts();
if (accounts.length > 0) {
handleAccountsChanged(accounts);
}
// ๊ณ์ ๋ณ๊ฒฝ ์ด๋ฒคํธ ๋ฆฌ์ค๋
window.ethereum.on('accountsChanged', handleAccountsChanged);
// ๋คํธ์ํฌ ๋ณ๊ฒฝ ์ด๋ฒคํธ ๋ฆฌ์ค๋
window.ethereum.on('chainChanged', () => {
window.location.reload();
});
} else {
showStatus('MetaMask๋ฅผ ์ค์นํด์ฃผ์ธ์!', 'error');
document.getElementById('connectButton').disabled = true;
}
// ๋คํธ์ํฌ ์ ๋ณด ๋ก๋
loadNetworkInfo();
// ๋ฒํผ ์ด๋ฒคํธ ๋ฆฌ์ค๋
document.getElementById('connectButton').addEventListener('click', connectWallet);
document.getElementById('signButton').addEventListener('click', signMessage);
document.getElementById('disconnectButton').addEventListener('click', disconnectWallet);
});
// ์ง๊ฐ ์ฐ๊ฒฐ ํจ์
async function connectWallet() {
try {
showStatus('์ง๊ฐ ์ฐ๊ฒฐ ์ค...', 'info');
// MetaMask ์ฐ๊ฒฐ ์์ฒญ
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts'
});
handleAccountsChanged(accounts);
showStatus('์ง๊ฐ์ด ์ฑ๊ณต์ ์ผ๋ก ์ฐ๊ฒฐ๋์์ต๋๋ค!', 'success');
} catch (error) {
console.error('์ง๊ฐ ์ฐ๊ฒฐ ์ค๋ฅ:', error);
if (error.code === 4001) {
showStatus('์ฌ์ฉ์๊ฐ ์ฐ๊ฒฐ์ ๊ฑฐ๋ถํ์ต๋๋ค.', 'error');
} else {
showStatus('์ง๊ฐ ์ฐ๊ฒฐ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.', 'error');
}
}
}
// ๊ณ์ ๋ณ๊ฒฝ ์ฒ๋ฆฌ
async function handleAccountsChanged(accounts) {
if (accounts.length === 0) {
// ์ฐ๊ฒฐ ํด์ ๋จ
document.getElementById('connect-section').style.display = 'block';
document.getElementById('wallet-info').style.display = 'none';
currentAccount = null;
} else {
currentAccount = accounts[0];
// UI ์
๋ฐ์ดํธ
document.getElementById('connect-section').style.display = 'none';
document.getElementById('wallet-info').style.display = 'block';
document.getElementById('walletAddress').textContent =
`${currentAccount.substring(0, 6)}...${currentAccount.substring(38)}`;
// ์์ก ์กฐํ
await updateBalance();
// ๋คํธ์ํฌ ์ ๋ณด ํ์
await updateNetworkInfo();
}
}
// ์์ก ์
๋ฐ์ดํธ
async function updateBalance() {
try {
const response = await fetch(`/api/balance/${currentAccount}`);
const data = await response.json();
if (data.success) {
const balance = parseFloat(data.balance_eth).toFixed(4);
document.getElementById('walletBalance').textContent = `${balance} ETH`;
}
} catch (error) {
console.error('์์ก ์กฐํ ์ค๋ฅ:', error);
}
}
// ๋คํธ์ํฌ ์ ๋ณด ์
๋ฐ์ดํธ
async function updateNetworkInfo() {
try {
const chainId = await web3.eth.getChainId();
const networkNames = {
1: 'Ethereum Mainnet',
5: 'Goerli Testnet',
11155111: 'Sepolia Testnet',
137: 'Polygon Mainnet',
80001: 'Mumbai Testnet'
};
const networkName = networkNames[chainId] || `Chain ID: ${chainId}`;
document.getElementById('networkName').textContent = networkName;
} catch (error) {
console.error('๋คํธ์ํฌ ์ ๋ณด ์กฐํ ์ค๋ฅ:', error);
}
}
// ๋คํธ์ํฌ ์ ๋ณด ๋ก๋ (๋ฐฑ์๋์์)
async function loadNetworkInfo() {
try {
const response = await fetch('/api/network-info');
const data = await response.json();
if (data.success) {
const infoHtml = `
<div class="info-item">
<span class="label">Chain ID:</span>
<span class="value">${data.chain_id}</span>
</div>
<div class="info-item">
<span class="label">์ต์ ๋ธ๋ก:</span>
<span class="value">${data.block_number.toLocaleString()}</span>
</div>
<div class="info-item">
<span class="label">Gas Price:</span>
<span class="value">${parseFloat(data.gas_price).toFixed(2)} Gwei</span>
</div>
`;
document.getElementById('networkData').innerHTML = infoHtml;
}
} catch (error) {
console.error('๋คํธ์ํฌ ์ ๋ณด ๋ก๋ ์ค๋ฅ:', error);
document.getElementById('networkData').textContent = '์ ๋ณด๋ฅผ ๋ถ๋ฌ์ฌ ์ ์์ต๋๋ค.';
}
}
// ๋ฉ์์ง ์๋ช
async function signMessage() {
try {
showStatus('์๋ช
์์ฒญ ์ค...', 'info');
// ๋ฐฑ์๋์์ nonce ์์ฒญ
const nonceResponse = await fetch(`/api/request-nonce/${currentAccount}`);
const nonceData = await nonceResponse.json();
if (!nonceData.success) {
throw new Error(nonceData.error);
}
const message = nonceData.message;
// MetaMask๋ก ์๋ช
์์ฒญ
const signature = await web3.eth.personal.sign(message, currentAccount);
// ๋ฐฑ์๋๋ก ์๋ช
๊ฒ์ฆ ์์ฒญ
const verifyResponse = await fetch('/api/verify-signature', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
address: currentAccount,
signature: signature
})
});
const verifyData = await verifyResponse.json();
if (verifyData.success) {
showStatus('โ
์๋ช
์ด ์ฑ๊ณต์ ์ผ๋ก ๊ฒ์ฆ๋์์ต๋๋ค!', 'success');
} else {
showStatus('โ ์๋ช
๊ฒ์ฆ์ ์คํจํ์ต๋๋ค.', 'error');
}
} catch (error) {
console.error('์๋ช
์ค๋ฅ:', error);
if (error.code === 4001) {
showStatus('์ฌ์ฉ์๊ฐ ์๋ช
์ ๊ฑฐ๋ถํ์ต๋๋ค.', 'error');
} else {
showStatus('์๋ช
์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.', 'error');
}
}
}
// ์ฐ๊ฒฐ ํด์
function disconnectWallet() {
currentAccount = null;
document.getElementById('connect-section').style.display = 'block';
document.getElementById('wallet-info').style.display = 'none';
showStatus('์ง๊ฐ ์ฐ๊ฒฐ์ด ํด์ ๋์์ต๋๋ค.', 'success');
}
// ์ํ ๋ฉ์์ง ํ์
function showStatus(message, type) {
const statusElement = document.getElementById('status-message');
statusElement.textContent = message;
statusElement.className = `status-message ${type}`;
// 3์ด ํ ์๋์ผ๋ก ์จ๊น
setTimeout(() => {
statusElement.style.display = 'none';
}, 3000);
}
๐ก Web3.js vs Ethers.js
์ด ์์ ์์๋ Web3.js๋ฅผ ์ฌ์ฉํ์ง๋ง, Ethers.js๋ ์ธ๊ธฐ ์๋ ๋์์ด์ผ. Ethers.js๋ ๋ ๊ฐ๋ณ๊ณ ๋ชจ๋ํ API๋ฅผ ์ ๊ณตํด. ํ๋ก์ ํธ ์๊ตฌ์ฌํญ์ ๋ฐ๋ผ ์ ํํ๋ฉด ๋ผ!
โข Web3.js: ์ค๋๋๊ณ ์์ ์ , ๋ ๋ง์ ๋ ํผ๋ฐ์ค
โข Ethers.js: ๊ฐ๋ณ๊ณ ๋น ๋ฆ, ํ์
์คํฌ๋ฆฝํธ ์ง์ ์ฐ์
๐ ์ค๋งํธ ์ปจํธ๋ํธ์ ์ํธ์์ฉํ๊ธฐ
์ง๊ฐ ์ฐ๋๋ง์ผ๋ก๋ ๋ถ์กฑํด! ์ง์ง Web3 ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ง๋ค๋ ค๋ฉด ์ค๋งํธ ์ปจํธ๋ํธ์ ์ํธ์์ฉํ ์ ์์ด์ผ ํด. ์ด์ ๊ทธ ๋ฐฉ๋ฒ์ ์์๋ณด์.
๐ ์ค๋งํธ ์ปจํธ๋ํธ ABI ์ดํดํ๊ธฐ
์ค๋งํธ ์ปจํธ๋ํธ์ ํต์ ํ๋ ค๋ฉด ABI(Application Binary Interface)๊ฐ ํ์ํด. ABI๋ ์ปจํธ๋ํธ์ ํจ์๋ค๊ณผ ์ด๋ฒคํธ๋ค์ ์ ์ํ JSON ํ์์ ์ธํฐํ์ด์ค์ผ. ์ฝ๊ฒ ๋งํ๋ฉด ์ปจํธ๋ํธ ์ฌ์ฉ ์ค๋ช ์๋ผ๊ณ ์๊ฐํ๋ฉด ๋ผ!
๊ฐ๋จํ ERC-20 ํ ํฐ ์ปจํธ๋ํธ๋ฅผ ์๋ก ๋ค์ด๋ณผ๊ฒ. ๋จผ์ contract.py ํ์ผ์ ๋ง๋ค์ด์ ์ปจํธ๋ํธ ๊ด๋ จ ํจ์๋ค์ ์ถ๊ฐํ์:
from web3 import Web3
import json
import os
# ERC-20 ํ ํฐ ํ์ค ABI (์ผ๋ถ)
ERC20_ABI = json.loads('''[
{
"constant": true,
"inputs": [{"name": "_owner", "type": "address"}],
"name": "balanceOf",
"outputs": [{"name": "balance", "type": "uint256"}],
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [{"name": "", "type": "uint256"}],
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [{"name": "", "type": "string"}],
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [{"name": "", "type": "string"}],
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{"name": "", "type": "uint8"}],
"type": "function"
},
{
"constant": false,
"inputs": [
{"name": "_to", "type": "address"},
{"name": "_value", "type": "uint256"}
],
"name": "transfer",
"outputs": [{"name": "", "type": "bool"}],
"type": "function"
}
]''')
class TokenContract:
def __init__(self, web3_instance, contract_address):
"""
ํ ํฐ ์ปจํธ๋ํธ ์ด๊ธฐํ
Args:
web3_instance: Web3 ์ธ์คํด์ค
contract_address: ์ปจํธ๋ํธ ์ฃผ์
"""
self.w3 = web3_instance
self.address = Web3.to_checksum_address(contract_address)
self.contract = self.w3.eth.contract(
address=self.address,
abi=ERC20_ABI
)
def get_token_info(self):
"""ํ ํฐ ๊ธฐ๋ณธ ์ ๋ณด ์กฐํ"""
try:
name = self.contract.functions.name().call()
symbol = self.contract.functions.symbol().call()
decimals = self.contract.functions.decimals().call()
total_supply = self.contract.functions.totalSupply().call()
return {
'success': True,
'name': name,
'symbol': symbol,
'decimals': decimals,
'total_supply': total_supply / (10 ** decimals)
}
except Exception as e:
return {
'success': False,
'error': str(e)
}
def get_balance(self, address):
"""ํน์ ์ฃผ์์ ํ ํฐ ์์ก ์กฐํ"""
try:
checksum_address = Web3.to_checksum_address(address)
balance = self.contract.functions.balanceOf(checksum_address).call()
decimals = self.contract.functions.decimals().call()
return {
'success': True,
'balance': balance / (10 ** decimals),
'balance_raw': balance
}
except Exception as e:
return {
'success': False,
'error': str(e)
}
def build_transfer_transaction(self, from_address, to_address, amount):
"""
ํ ํฐ ์ ์ก ํธ๋์ญ์
์์ฑ
(์ค์ ์ ์ก์ ํ๋ก ํธ์๋์์ MetaMask๋ฅผ ํตํด ์ํ)
"""
try:
from_checksum = Web3.to_checksum_address(from_address)
to_checksum = Web3.to_checksum_address(to_address)
decimals = self.contract.functions.decimals().call()
amount_wei = int(amount * (10 ** decimals))
# ํธ๋์ญ์
๋ฐ์ดํฐ ์์ฑ
transaction = self.contract.functions.transfer(
to_checksum,
amount_wei
).build_transaction({
'from': from_checksum,
'gas': 100000,
'gasPrice': self.w3.eth.gas_price,
'nonce': self.w3.eth.get_transaction_count(from_checksum)
})
return {
'success': True,
'transaction': transaction
}
except Exception as e:
return {
'success': False,
'error': str(e)
}
์ด์ app.py์ ํ ํฐ ๊ด๋ จ ์๋ํฌ์ธํธ๋ฅผ ์ถ๊ฐํ์:
from contract import TokenContract
@app.route('/api/token/info/<contract_address>')
def get_token_info(contract_address):
"""ํ ํฐ ์ ๋ณด ์กฐํ"""
try:
token = TokenContract(w3, contract_address)
info = token.get_token_info()
return jsonify(info)
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
@app.route('/api/token/balance/<contract_address>/<wallet_address>')
def get_token_balance(contract_address, wallet_address):
"""ํ ํฐ ์์ก ์กฐํ"""
try:
token = TokenContract(w3, contract_address)
balance = token.get_balance(wallet_address)
return jsonify(balance)
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
@app.route('/api/token/transfer', methods=['POST'])
def prepare_token_transfer():
"""ํ ํฐ ์ ์ก ํธ๋์ญ์
์ค๋น"""
try:
data = request.json
contract_address = data.get('contract_address')
from_address = data.get('from_address')
to_address = data.get('to_address')
amount = float(data.get('amount'))
token = TokenContract(w3, contract_address)
result = token.build_transfer_transaction(
from_address,
to_address,
amount
)
return jsonify(result)
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
๐ธ ํ๋ก ํธ์๋์์ ํ ํฐ ์ ์กํ๊ธฐ
wallet.js์ ํ ํฐ ์ ์ก ๊ธฐ๋ฅ์ ์ถ๊ฐํด๋ณด์:
// ํ ํฐ ์ ์ก ํจ์
async function sendToken(contractAddress, toAddress, amount) {
try {
showStatus('ํธ๋์ญ์
์ค๋น ์ค...', 'info');
// ๋ฐฑ์๋์์ ํธ๋์ญ์
๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
const response = await fetch('/api/token/transfer', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
contract_address: contractAddress,
from_address: currentAccount,
to_address: toAddress,
amount: amount
})
});
const data = await response.json();
if (!data.success) {
throw new Error(data.error);
}
// MetaMask๋ก ํธ๋์ญ์
์ ์ก
const txHash = await window.ethereum.request({
method: 'eth_sendTransaction',
params: [data.transaction]
});
showStatus(`ํธ๋์ญ์
์ ์ก ์๋ฃ! Hash: ${txHash}`, 'success');
// ํธ๋์ญ์
ํ์ธ ๋๊ธฐ
await waitForTransaction(txHash);
return txHash;
} catch (error) {
console.error('ํ ํฐ ์ ์ก ์ค๋ฅ:', error);
showStatus('ํ ํฐ ์ ์ก ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.', 'error');
throw error;
}
}
// ํธ๋์ญ์
ํ์ธ ๋๊ธฐ
async function waitForTransaction(txHash) {
showStatus('ํธ๋์ญ์
ํ์ธ ๋๊ธฐ ์ค...', 'info');
let receipt = null;
while (receipt === null) {
try {
receipt = await web3.eth.getTransactionReceipt(txHash);
if (receipt === null) {
await new Promise(resolve => setTimeout(resolve, 2000));
}
} catch (error) {
console.error('์์์ฆ ์กฐํ ์ค๋ฅ:', error);
}
}
if (receipt.status) {
showStatus('โ
ํธ๋์ญ์
์ด ์ฑ๊ณต์ ์ผ๋ก ์๋ฃ๋์์ต๋๋ค!', 'success');
} else {
showStatus('โ ํธ๋์ญ์
์ด ์คํจํ์ต๋๋ค.', 'error');
}
return receipt;
}
// ํ ํฐ ์ ๋ณด ์กฐํ
async function getTokenInfo(contractAddress) {
try {
const response = await fetch(`/api/token/info/${contractAddress}`);
const data = await response.json();
if (data.success) {
return {
name: data.name,
symbol: data.symbol,
decimals: data.decimals,
totalSupply: data.total_supply
};
} else {
throw new Error(data.error);
}
} catch (error) {
console.error('ํ ํฐ ์ ๋ณด ์กฐํ ์ค๋ฅ:', error);
return null;
}
}
โ ๏ธ ๊ฐ์ค๋น(Gas Fee) ์ฃผ์์ฌํญ
๋ธ๋ก์ฒด์ธ ํธ๋์ญ์
์ ์คํํ ๋๋ ํญ์ ๊ฐ์ค๋น๊ฐ ๋ฐ์ํด. ํนํ ์ด๋๋ฆฌ์ ๋ฉ์ธ๋ท์์๋ ๊ฐ์ค๋น๊ฐ ์๋นํ ๋น์ ์ ์์ด. ๊ฐ๋ฐ ๋จ๊ณ์์๋ ๋ค์ ํ
์คํธ๋ท์ ์ฌ์ฉํ๋ ๊ฑธ ๊ฐ๋ ฅํ ์ถ์ฒํด:
โข Sepolia Testnet: ๊ฐ์ฅ ์ต์ ์ ์ด๋๋ฆฌ์ ํ
์คํธ๋ท
โข Goerli Testnet: ์์ ์ ์ด๊ณ ๋๋ฆฌ ์ฌ์ฉ๋จ
โข Mumbai Testnet: Polygon ํ
์คํธ๋ท (๋น ๋ฅด๊ณ ์ ๋ ด)
ํ
์คํธ๋ท ETH๋ Faucet์์ ๋ฌด๋ฃ๋ก ๋ฐ์ ์ ์์ด!
๐ ๋ณด์ ๊ณ ๋ ค์ฌํญ
๋ธ๋ก์ฒด์ธ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฐ๋ฐํ ๋ ๋ณด์์ ์ ๋ง์ ๋ง ์ค์ํด! ํ ๋ฒ ์ค์ํ๋ฉด ๋์ด ๋ ์๊ฐ๊ฑฐ๋ ํดํน๋นํ ์ ์๊ฑฐ๋ . ๊ผญ ์์์ผ ํ ๋ณด์ ์ฌํญ๋ค์ ์ ๋ฆฌํด๋ดค์ด.
๐ก๏ธ ํ๋ก ํธ์๋ ๋ณด์
1. ๊ฐ์ธํค๋ ์ ๋ ํ๋ก ํธ์๋์ ์ ์ฅํ์ง ๋ง!
๊ฐ์ธํค๋ MetaMask ๊ฐ์ ์ง๊ฐ์ด ๊ด๋ฆฌํ๋๋ก ํด์ผ ํด. ์น ์ ํ๋ฆฌ์ผ์ด์
์ฝ๋์ ๊ฐ์ธํค๋ฅผ ํ๋์ฝ๋ฉํ๊ฑฐ๋ ๋ก์ปฌ ์คํ ๋ฆฌ์ง์ ์ ์ฅํ๋ฉด ์ ๋ ์ ๋ผ!
2. ์
๋ ฅ๊ฐ ๊ฒ์ฆ์ ํ์
์ฌ์ฉ์๊ฐ ์
๋ ฅํ ์ฃผ์, ๊ธ์ก ๋ฑ์ ํญ์ ๊ฒ์ฆํด์ผ ํด. Web3.js์ isAddress() ํจ์๋ฅผ ํ์ฉํ์.
3. HTTPS ์ฌ์ฉ
ํ๋ก๋์
ํ๊ฒฝ์์๋ ๋ฐ๋์ HTTPS๋ฅผ ์ฌ์ฉํด์ผ ํด. HTTP์์๋ ์ค๊ฐ์ ๊ณต๊ฒฉ(Man-in-the-Middle)์ ์ทจ์ฝํด.
4. XSS(Cross-Site Scripting) ๋ฐฉ์ง
์ฌ์ฉ์ ์
๋ ฅ์ ๊ทธ๋๋ก HTML์ ๋ ๋๋งํ์ง ๋ง๊ณ , ํญ์ ์ด์ค์ผ์ดํ ์ฒ๋ฆฌ๋ฅผ ํด์ผ ํด.
๐ ๋ฐฑ์๋ ๋ณด์
1. API ํค ๋ณดํธ
Infura๋ Alchemy API ํค๋ ํ๊ฒฝ ๋ณ์๋ก ๊ด๋ฆฌํ๊ณ , .env ํ์ผ์ ์ ๋ git์ ์ฌ๋ฆฌ์ง ๋ง!
2. Rate Limiting ์ ์ฉ
๋ฌด์ฐจ๋ณ ๋์
๊ณต๊ฒฉ์ ๋ฐฉ์งํ๊ธฐ ์ํด API ์์ฒญ ํ์๋ฅผ ์ ํํด์ผ ํด. Flask-Limiter ๊ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด ์ฝ๊ฒ ๊ตฌํํ ์ ์์ด.
3. CORS ์ค์ ์ฃผ์
๋ชจ๋ ๋๋ฉ์ธ์์ ์ ๊ทผ์ ํ์ฉํ๋ฉด ์ ๋ผ. ํน์ ๋๋ฉ์ธ๋ง ํ์ฉํ๋๋ก ์ค์ ํ์.
4. SQL Injection ๋ฐฉ์ง
๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ORM์ ์ฌ์ฉํ๊ฑฐ๋ ํ๋ผ๋ฏธํฐํ๋ ์ฟผ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ผ ํด.
โก ์ค๋งํธ ์ปจํธ๋ํธ ๋ณด์
1. ์ฌ์ง์
๊ณต๊ฒฉ(Reentrancy) ๋ฐฉ์ง
์ธ๋ถ ์ปจํธ๋ํธ๋ฅผ ํธ์ถํ๊ธฐ ์ ์ ์ํ๋ฅผ ๋จผ์ ์
๋ฐ์ดํธํด์ผ ํด. ์ ๋ช
ํ DAO ํดํน ์ฌ๊ฑด์ด ์ด ์ทจ์ฝ์ ๋๋ฌธ์ ๋ฐ์ํ์ด.
2. ์ ์ ์ค๋ฒํ๋ก์ฐ/์ธ๋ํ๋ก์ฐ ๋ฐฉ์ง
Solidity 0.8.0 ์ด์์์๋ ์๋์ผ๋ก ์ฒดํฌ๋์ง๋ง, ์ด์ ๋ฒ์ ์์๋ SafeMath ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ผ ํด.
3. ๊ฐ์ค ํ๋ ๊ณ ๋ ค
๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉํ ๋๋ ๊ฐ์ค ํ๋๋ฅผ ์ด๊ณผํ์ง ์๋๋ก ์ฃผ์ํด์ผ ํด. ๋ฌดํ ๋ฃจํ๋ ์ ๋ ๊ธ๋ฌผ!
4. ์ ๊ทผ ์ ์ด
์ค์ํ ํจ์๋ onlyOwner ๊ฐ์ modifier๋ก ๋ณดํธํด์ผ ํด.
๐จ ์ค์ ๋ณด์ ์ฒดํฌ๋ฆฌ์คํธ
๋ฐฐํฌ ์ ์ ๊ผญ ํ์ธํด์ผ ํ ์ฌํญ๋ค:
โ
๋ชจ๋ ํ๊ฒฝ ๋ณ์๊ฐ .env ํ์ผ์ ์๊ณ git์์ ์ ์ธ๋์๋๊ฐ?
โ
API ์๋ํฌ์ธํธ์ ์ธ์ฆ์ด ์ ์ฉ๋์๋๊ฐ?
โ
Rate limiting์ด ์ค์ ๋์๋๊ฐ?
โ
HTTPS๊ฐ ์ ์ฉ๋์๋๊ฐ?
โ
์๋ฌ ๋ฉ์์ง์ ๋ฏผ๊ฐํ ์ ๋ณด๊ฐ ํฌํจ๋์ง ์์๋๊ฐ?
โ
์ค๋งํธ ์ปจํธ๋ํธ ๊ฐ์ฌ(Audit)๋ฅผ ๋ฐ์๋๊ฐ?
โ
ํ
์คํธ๋ท์์ ์ถฉ๋ถํ ํ
์คํธํ๋๊ฐ?
๐ ๋ฐฐํฌ ๋ฐ ์ต์ ํ
๊ฐ๋ฐ์ด ์๋ฃ๋์๋ค๋ฉด ์ด์ ์ค์ ์๋น์ค๋ก ๋ฐฐํฌํ ์ฐจ๋ก์ผ! ๋ฐฐํฌ ๊ณผ์ ๊ณผ ์ฑ๋ฅ ์ต์ ํ ๋ฐฉ๋ฒ์ ์์๋ณด์.
โ๏ธ ํด๋ผ์ฐ๋ ๋ฐฐํฌ ์ต์
| ํ๋ซํผ | ์ฅ์ | ๋จ์ | ์ถ์ฒ ์ฉ๋ |
|---|---|---|---|
| Heroku | ๊ฐ๋จํ ๋ฐฐํฌ, ๋ฌด๋ฃ ํ๋ | ์ฑ๋ฅ ์ ํ, ๋น์ฉ ์ฆ๊ฐ | ํ๋กํ ํ์ , ์๊ท๋ชจ |
| AWS EC2 | ๋์ ์ ์ฐ์ฑ, ํ์ฅ์ฑ | ๋ณต์กํ ์ค์ , ๊ด๋ฆฌ ํ์ | ๋๊ท๋ชจ ์๋น์ค |
| DigitalOcean | ๊ฐ๋จํ ์ธํฐํ์ด์ค, ์ ๋ ด | AWS๋ณด๋ค ๊ธฐ๋ฅ ์ ํ์ | ์ค์๊ท๋ชจ ์๋น์ค |
| Vercel | ์๋ ๋ฐฐํฌ, ๋น ๋ฅธ CDN | ๋ฐฑ์๋ ์ ํ์ | ํ๋ก ํธ์๋ ์ค์ฌ |
| Railway | ๊ฐ๋จํ ๋ฐฐํฌ, ์ข์ DX | ์๋์ ์ผ๋ก ์ ์ | ํ์คํ ์ฑ |
โ๏ธ ํ๋ก๋์ ์ค์
ํ๋ก๋์ ํ๊ฒฝ์์๋ ๊ฐ๋ฐ ํ๊ฒฝ๊ณผ ๋ค๋ฅธ ์ค์ ์ด ํ์ํด. config.py ํ์ผ์ ์์ ํด์ ํ๊ฒฝ๋ณ ์ค์ ์ ๊ด๋ฆฌํ์:
import os
from dotenv import load_dotenv
load_dotenv()
class Config:
"""๊ธฐ๋ณธ ์ค์ """
SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key')
INFURA_URL = os.getenv('INFURA_URL')
class DevelopmentConfig(Config):
"""๊ฐ๋ฐ ํ๊ฒฝ ์ค์ """
DEBUG = True
TESTING = False
class ProductionConfig(Config):
"""ํ๋ก๋์
ํ๊ฒฝ ์ค์ """
DEBUG = False
TESTING = False
# ๋ณด์ ํค๋ ์ค์
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'Lax'
class TestingConfig(Config):
"""ํ
์คํธ ํ๊ฒฝ ์ค์ """
DEBUG = True
TESTING = True
# ํ๊ฒฝ์ ๋ฐ๋ผ ์ค์ ์ ํ
config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig,
'default': DevelopmentConfig
}
app.py๋ฅผ ์์ ํด์ ํ๊ฒฝ๋ณ ์ค์ ์ ์ ์ฉํ์:
from config import config
import os
# ํ๊ฒฝ ๋ณ์์์ ์ค์ ๊ฐ์ ธ์ค๊ธฐ (๊ธฐ๋ณธ๊ฐ: development)
config_name = os.getenv('FLASK_ENV', 'development')
app.config.from_object(config[config_name])
# ํ๋ก๋์
์์๋ Gunicorn ์ฌ์ฉ
if __name__ == '__main__':
if config_name == 'development':
app.run(debug=True, port=5000)
else:
# ํ๋ก๋์
์์๋ Gunicorn์ผ๋ก ์คํ
# gunicorn -w 4 -b 0.0.0.0:5000 app:app
pass
โก ์ฑ๋ฅ ์ต์ ํ
๐ก ์บ์ฑ ์ ๋ต ๋ธ๋ก์ฒด์ธ ๋ฐ์ดํฐ ์กฐํ๋ ์๊ฐ์ด ๊ฑธ๋ฆด ์ ์์ด. ์์ฃผ ๋ณํ์ง ์๋ ๋ฐ์ดํฐ๋ ์บ์ฑํ์!
from flask_caching import Cache
# ์บ์ ์ค์
cache = Cache(app, config={
'CACHE_TYPE': 'redis',
'CACHE_REDIS_URL': os.getenv('REDIS_URL', 'redis://localhost:6379/0')
})
@app.route('/api/token/info/<contract_address>')
@cache.cached(timeout=3600) # 1์๊ฐ ์บ์ฑ
def get_token_info(contract_address):
"""ํ ํฐ ์ ๋ณด ์กฐํ (์บ์ฑ ์ ์ฉ)"""
try:
token = TokenContract(w3, contract_address)
info = token.get_token_info()
return jsonify(info)
except Exception as e:
return jsonify({
'success': False,
'error': str(e)
}), 500
ํ๋ก ํธ์๋ ์ต์ ํ ํ
1. ๋ฒ๋ค ํฌ๊ธฐ ์ค์ด๊ธฐ: Web3.js ๋์ Ethers.js ์ฌ์ฉ ๊ณ ๋ ค (๋ ๊ฐ๋ฒผ์)
2. ์ฝ๋ ์คํ๋ฆฌํ
: ํ์ํ ์์ ์๋ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ก๋
3. ์ด๋ฏธ์ง ์ต์ ํ: WebP ํฌ๋งท ์ฌ์ฉ, ์ ์ ํ ํฌ๊ธฐ๋ก ๋ฆฌ์ฌ์ด์ง
4. CDN ํ์ฉ: ์ ์ ํ์ผ์ CDN์ ํตํด ์ ๊ณต
5. Lazy Loading: ํ๋ฉด์ ๋ณด์ด๋ ๋ถ๋ถ๋ง ๋จผ์ ๋ก๋
๐ ๋ชจ๋ํฐ๋ง ๋ฐ ๋ก๊น
ํ๋ก๋์ ํ๊ฒฝ์์๋ ์๋ฌ๋ฅผ ๋น ๋ฅด๊ฒ ๊ฐ์งํ๊ณ ๋์ํ๋ ๊ฒ ์ค์ํด. ๋ก๊น ์์คํ ์ ๊ตฌ์ถํด๋ณด์:
import logging
from logging.handlers import RotatingFileHandler
import os
# ๋ก๊ทธ ๋๋ ํ ๋ฆฌ ์์ฑ
if not os.path.exists('logs'):
os.mkdir('logs')
# ํ์ผ ํธ๋ค๋ฌ ์ค์
file_handler = RotatingFileHandler(
'logs/blockchain_app.log',
maxBytes=10240000, # 10MB
backupCount=10
)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'
))
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('๋ธ๋ก์ฒด์ธ ์ฑ ์์')
# ์๋ฌ ํธ๋ค๋ฌ
@app.errorhandler(500)
def internal_error(error):
app.logger.error(f'์๋ฒ ์ค๋ฅ: {error}')
return jsonify({
'success': False,
'error': '๋ด๋ถ ์๋ฒ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.'
}), 500
@app.errorhandler(404)
def not_found_error(error):
return jsonify({
'success': False,
'error': '์์ฒญํ ๋ฆฌ์์ค๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.'
}), 404
๐ ์ถ์ฒ ๋ชจ๋ํฐ๋ง ๋๊ตฌ
โข Sentry: ์๋ฌ ์ถ์ ๋ฐ ์๋ฆผ
โข Datadog: ์ข
ํฉ ๋ชจ๋ํฐ๋ง ํ๋ซํผ
โข New Relic: ์ ํ๋ฆฌ์ผ์ด์
์ฑ๋ฅ ๋ชจ๋ํฐ๋ง
โข Prometheus + Grafana: ์คํ์์ค ๋ชจ๋ํฐ๋ง ์คํ
๐ ์ค์ ํ๋ก์ ํธ ์์ด๋์ด
์ด์ ๊ธฐ๋ณธ๊ธฐ๋ฅผ ๋ค ๋ฐฐ์ ์ผ๋, ์ค์ ๋ก ๋ง๋ค์ด๋ณผ ์ ์๋ ํ๋ก์ ํธ ์์ด๋์ด๋ค์ ์๊ฐํ ๊ฒ! ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์๋ ์ด๋ฐ ๋ธ๋ก์ฒด์ธ ๊ธฐ์ ์ ํ์ฉํ ์๋น์ค๋ฅผ ์ ๊ณตํ ์ ์์ ๊ฑฐ์ผ.
๐จ 1. NFT ๋ง์ผํ๋ ์ด์ค
ํต์ฌ ๊ธฐ๋ฅ:
โข NFT ๋ฏผํ
(๋ฐํ) ๊ธฐ๋ฅ
โข NFT ๊ฑฐ๋ ๋ฐ ๊ฒฝ๋งค
โข ์ฌ์ฉ์ ํ๋กํ ๋ฐ ์ปฌ๋ ์
๊ด๋ฆฌ
โข IPFS๋ฅผ ํ์ฉํ ๋ฉํ๋ฐ์ดํฐ ์ ์ฅ
๊ธฐ์ ์คํ:
โข ํ๋ก ํธ์๋: React + Web3.js
โข ๋ฐฑ์๋: Flask + PostgreSQL
โข ์ค๋งํธ ์ปจํธ๋ํธ: Solidity (ERC-721)
โข ์ ์ฅ์: IPFS ๋๋ Arweave
๋์ด๋: โญโญโญโญ (์ค์๊ธ)
๐ฐ 2. ํ์ค์ํ ํฌ๋ผ์ฐ๋ํ๋ฉ ํ๋ซํผ
ํต์ฌ ๊ธฐ๋ฅ:
โข ํ๋ก์ ํธ ๋ฑ๋ก ๋ฐ ํ๋ฉ ๋ชฉํ ์ค์
โข ์ํธํํ๋ก ํ์ํ๊ธฐ
โข ๋ชฉํ ๋ฌ์ฑ ์ ์๋ ์ ์ฐ
โข ํฌ๋ช
ํ ์๊ธ ์ฌ์ฉ ๋ด์ญ ๊ณต๊ฐ
๊ธฐ์ ์คํ:
โข ํ๋ก ํธ์๋: Vue.js + Ethers.js
โข ๋ฐฑ์๋: Flask + MongoDB
โข ์ค๋งํธ ์ปจํธ๋ํธ: Solidity
๋์ด๋: โญโญโญ (์ค๊ธ)
๐ฎ 3. ๋ธ๋ก์ฒด์ธ ๊ฒ์ ์์ดํ ๊ฑฐ๋์
ํต์ฌ ๊ธฐ๋ฅ:
โข ๊ฒ์ ์์ดํ
NFTํ
โข P2P ๊ฑฐ๋ ์์คํ
โข ์์ดํ
๋์ฌ ๊ธฐ๋ฅ
โข ๊ฒ์ ๊ฐ ์์ดํ
ํธํ์ฑ
๊ธฐ์ ์คํ:
โข ํ๋ก ํธ์๋: Next.js + Web3Modal
โข ๋ฐฑ์๋: Flask + Redis
โข ์ค๋งํธ ์ปจํธ๋ํธ: Solidity (ERC-1155)
๋์ด๋: โญโญโญโญโญ (๊ณ ๊ธ)
๐ 4. DAO ํฌํ ์์คํ
ํต์ฌ ๊ธฐ๋ฅ:
โข ์ ์์ ์์ฑ ๋ฐ ํฌํ
โข ํ ํฐ ๊ธฐ๋ฐ ํฌํ๊ถ
โข ํฌํ ๊ฒฐ๊ณผ ์๋ ์คํ
โข ํฌ๋ช
ํ ๊ฑฐ๋ฒ๋์ค
๊ธฐ์ ์คํ:
โข ํ๋ก ํธ์๋: React + Web3.js
โข ๋ฐฑ์๋: Flask + PostgreSQL
โข ์ค๋งํธ ์ปจํธ๋ํธ: Solidity
๋์ด๋: โญโญโญโญ (์ค์๊ธ)
๐ 5. ๋ํ์ด(DeFi) ์คํ ์ดํน ํ๋ซํผ
ํต์ฌ ๊ธฐ๋ฅ:
โข ํ ํฐ ์คํ
์ดํน
โข ์๋ ๋ณด์ ๋ถ๋ฐฐ
โข APY ๊ณ์ฐ ๋ฐ ํ์
โข ์ ๋์ฑ ํ ๊ด๋ฆฌ
๊ธฐ์ ์คํ:
โข ํ๋ก ํธ์๋: React + Ethers.js
โข ๋ฐฑ์๋: Flask + Redis
โข ์ค๋งํธ ์ปจํธ๋ํธ: Solidity
๋์ด๋: โญโญโญโญโญ (๊ณ ๊ธ)
๐ก ํ๋ก์ ํธ ์์ ์ ์ฒดํฌ๋ฆฌ์คํธ
โ
๋ช
ํํ ๋ฌธ์ ์ ์์ ํด๊ฒฐ ๋ฐฉ์
โ
ํ๊ฒ ์ฌ์ฉ์ ๋ถ์
โ
๊ฒฝ์ ์๋น์ค ์กฐ์ฌ
โ
๊ธฐ์ ์คํ ์ ์
โ
MVP(์ต์ ๊ธฐ๋ฅ ์ ํ) ๋ฒ์ ์ ์
โ
๊ฐ๋ฐ ์ผ์ ๋ฐ ๋ง์ผ์คํค ์ค์
โ
๋ณด์ ๊ฐ์ฌ ๊ณํ
โ
๋ฒ์ ๊ท์ ํ์ธ
๐ ์์ฃผ ๋ฐ์ํ๋ ๋ฌธ์ ์ ํด๊ฒฐ๋ฒ
๊ฐ๋ฐํ๋ค ๋ณด๋ฉด ๋๊ตฌ๋ ๋ฌธ์ ์ ๋ถ๋ชํ๊ฒ ๋ผ. ๋ด๊ฐ ๊ฒฝํํ๋ ํํ ๋ฌธ์ ๋ค๊ณผ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๊ณต์ ํ ๊ฒ!
โ ๋ฌธ์ 1: MetaMask ์ฐ๊ฒฐ์ด ์ ๋ผ์!
์ฆ์: ์ฐ๊ฒฐ ๋ฒํผ์ ๋๋ฌ๋ MetaMask ํ์
์ด ๋จ์ง ์์
์์ธ:
โข MetaMask๊ฐ ์ค์น๋์ง ์์
โข ๋ธ๋ผ์ฐ์ ๊ฐ MetaMask๋ฅผ ์ง์ํ์ง ์์
โข window.ethereum ๊ฐ์ฒด๊ฐ ๋ก๋๋๊ธฐ ์ ์ ์ ๊ทผ
ํด๊ฒฐ ๋ฐฉ๋ฒ:
// MetaMask ๊ฐ์ง ๊ฐ์
async function detectMetaMask() {
// Ethereum ๊ฐ์ฒด๊ฐ ๋ก๋๋ ๋๊น์ง ๋๊ธฐ
if (typeof window.ethereum === 'undefined') {
let attempts = 0;
const maxAttempts = 10;
while (attempts < maxAttempts) {
await new Promise(resolve => setTimeout(resolve, 100));
if (typeof window.ethereum !== 'undefined') {
return true;
}
attempts++;
}
alert('MetaMask๋ฅผ ์ค์นํด์ฃผ์ธ์!\nhttps://metamask.io');
return false;
}
return true;
}
// ์ฌ์ฉ ์์
window.addEventListener('load', async () => {
const hasMetaMask = await detectMetaMask();
if (hasMetaMask) {
web3 = new Web3(window.ethereum);
// ๋๋จธ์ง ์ด๊ธฐํ ์ฝ๋...
}
});
โ ๋ฌธ์ 2: ํธ๋์ญ์ ์ด ์คํจํด์!
์ฆ์: ํธ๋์ญ์
์ ์ ์กํ๋๋ฐ ์คํจํจ
์์ธ:
โข ๊ฐ์ค๋น ๋ถ์กฑ
โข ๊ฐ์ค ํ๋ ์ค์ ์ด ๋๋ฌด ๋ฎ์
โข ์ค๋งํธ ์ปจํธ๋ํธ ๋ก์ง ์ค๋ฅ
โข ๋คํธ์ํฌ ํผ์ก
ํด๊ฒฐ ๋ฐฉ๋ฒ:
// ๊ฐ์ค ์ถ์ ๋ฐ ์์ ๋ง์ง ์ถ๊ฐ
async function sendTransactionSafely(transaction) {
try {
// ๊ฐ์ค ์ถ์
const estimatedGas = await web3.eth.estimateGas(transaction);
// 20% ์์ ๋ง์ง ์ถ๊ฐ
const gasLimit = Math.floor(estimatedGas * 1.2);
// ํ์ฌ ๊ฐ์ค ๊ฐ๊ฒฉ ์กฐํ
const gasPrice = await web3.eth.getGasPrice();
// ํธ๋์ญ์
์ ๊ฐ์ค ์ค์ ์ถ๊ฐ
transaction.gas = gasLimit;
transaction.gasPrice = gasPrice;
// ํธ๋์ญ์
์ ์ก
const txHash = await window.ethereum.request({
method: 'eth_sendTransaction',
params: [transaction]
});
return txHash;
} catch (error) {
console.error('ํธ๋์ญ์
์ค๋ฅ:', error);
// ์ค๋ฅ ๋ฉ์์ง ๋ถ์
if (error.message.includes('insufficient funds')) {
alert('์์ก์ด ๋ถ์กฑํฉ๋๋ค. ETH๋ฅผ ์ถฉ์ ํด์ฃผ์ธ์.');
} else if (error.message.includes('gas required exceeds')) {
alert('๊ฐ์ค ํ๋๋ฅผ ์ด๊ณผํ์ต๋๋ค. ํธ๋์ญ์
์ ํ์ธํด์ฃผ์ธ์.');
} else {
alert('ํธ๋์ญ์
์คํจ: ' + error.message);
}
throw error;
}
}
โ ๋ฌธ์ 3: ์์ก์ด ์ ๋๋ก ํ์๋์ง ์์์!
์ฆ์: ์ง๊ฐ ์์ก์ด 0์ผ๋ก ํ์๋๊ฑฐ๋ ์ด์ํ ๊ฐ์ด ๋์ด
์์ธ:
โข Wei ๋จ์ ๋ณํ ๋ฌธ์
โข ๋น๋๊ธฐ ์ฒ๋ฆฌ ์ค๋ฅ
โข ๋คํธ์ํฌ ์ฐ๊ฒฐ ๋ฌธ์
ํด๊ฒฐ ๋ฐฉ๋ฒ:
// ์์ ํ ์์ก ์กฐํ
async function getBalanceSafely(address) {
try {
// ์ฃผ์ ์ ํจ์ฑ ๊ฒ์ฌ
if (!web3.utils.isAddress(address)) {
throw new Error('์ ํจํ์ง ์์ ์ฃผ์์
๋๋ค');
}
// ์ฒดํฌ์ฌ ์ฃผ์๋ก ๋ณํ
const checksumAddress = web3.utils.toChecksumAddress(address);
// ์์ก ์กฐํ (Wei ๋จ์)
const balanceWei = await web3.eth.getBalance(checksumAddress);
// ETH ๋จ์๋ก ๋ณํ
const balanceEth = web3.utils.fromWei(balanceWei, 'ether');
// ์์์ 4์๋ฆฌ๊น์ง ํ์
const balanceFormatted = parseFloat(balanceEth).toFixed(4);
return {
wei: balanceWei,
eth: balanceEth,
formatted: balanceFormatted
};
} catch (error) {
console.error('์์ก ์กฐํ ์ค๋ฅ:', error);
return {
wei: '0',
eth: '0',
formatted: '0.0000'
};
}
}
โ ๋ฌธ์ 4: CORS ์๋ฌ๊ฐ ๋ฐ์ํด์!
์ฆ์: ๋ธ๋ผ์ฐ์ ์ฝ์์ CORS ๊ด๋ จ ์๋ฌ ๋ฉ์์ง
์์ธ:
โข Flask ์๋ฒ์์ CORS ์ค์ ์ด ์ ๋จ
โข ์๋ชป๋ ๋๋ฉ์ธ ์ค์
ํด๊ฒฐ ๋ฐฉ๋ฒ:
from flask_cors import CORS
# ๊ฐ๋ฐ ํ๊ฒฝ: ๋ชจ๋ ๋๋ฉ์ธ ํ์ฉ
if app.config['DEBUG']:
CORS(app)
else:
# ํ๋ก๋์
: ํน์ ๋๋ฉ์ธ๋ง ํ์ฉ
CORS(app, resources={
r"/api/*": {
"origins": [
"https://yourdomain.com",
"https://www.yourdomain.com"
],
"methods": ["GET", "POST", "PUT", "DELETE"],
"allow_headers": ["Content-Type", "Authorization"]
}
})
โ ๋ฌธ์ 5: ์๋ช ๊ฒ์ฆ์ด ์คํจํด์!
์ฆ์: ๋ฉ์์ง ์๋ช
ํ ๊ฒ์ฆ์ด ๊ณ์ ์คํจํจ
์์ธ:
โข ๋ฉ์์ง ํฌ๋งท์ด ํ๋ก ํธ์๋์ ๋ฐฑ์๋์์ ๋ค๋ฆ
โข ์ฃผ์ ๋์๋ฌธ์ ๋ฌธ์
โข ์๋ช
๋ฐฉ์ ๋ถ์ผ์น
ํด๊ฒฐ ๋ฐฉ๋ฒ:
# ๋ฐฑ์๋ (Python)
from eth_account.messages import encode_defunct
def verify_signature(address, message, signature):
try:
w3 = Web3()
# ๋ฉ์์ง ์ธ์ฝ๋ฉ (์ ํํ ๊ฐ์ ๋ฐฉ์์ผ๋ก)
message_hash = encode_defunct(text=message)
# ์๋ช
์ผ๋ก๋ถํฐ ์ฃผ์ ๋ณต๊ตฌ
recovered_address = w3.eth.account.recover_message(
message_hash,
signature=signature
)
# ๋์๋ฌธ์ ๊ตฌ๋ถ ์์ด ๋น๊ต
return recovered_address.lower() == address.lower()
except Exception as e:
print(f"๊ฒ์ฆ ์ค๋ฅ: {e}")
return False
# ํ๋ก ํธ์๋ (JavaScript)
async function signMessage(message) {
try {
// personal_sign ์ฌ์ฉ (MetaMask ๊ถ์ฅ ๋ฐฉ์)
const signature = await web3.eth.personal.sign(
message,
currentAccount,
'' // ๋น๋ฐ๋ฒํธ (MetaMask์์๋ ๋ถํ์)
);
return signature;
} catch (error) {
console.error('์๋ช
์ค๋ฅ:', error);
throw error;
}
}
๐ ๋๋ฒ๊น
ํ
๋ฌธ์ ๊ฐ ๋ฐ์ํ์ ๋ ํ์ธํ ์ฌํญ๋ค:
1. ๋ธ๋ผ์ฐ์ ๊ฐ๋ฐ์ ๋๊ตฌ ์ฝ์ ํ์ธ
2. ๋คํธ์ํฌ ํญ์์ API ์์ฒญ/์๋ต ํ์ธ
3. MetaMask ํ๋ ๋ก๊ทธ ํ์ธ
4. ๋ฐฑ์๋ ๋ก๊ทธ ํ์ธ
5. ๋ธ๋ก์ฒด์ธ ์ต์คํ๋ก๋ฌ์์ ํธ๋์ญ์
์ํ ํ์ธ
6. ํ
์คํธ๋ท์์ ๋จผ์ ํ
์คํธ
7. ๊ฐ์ค๋น๊ฐ ์ถฉ๋ถํ์ง ํ์ธ
๐ ๋ ๊ณต๋ถํ๋ฉด ์ข์ ๊ฒ๋ค
์ฌ๊ธฐ๊น์ง ์๋ค๋ฉด ์ ๋ง ๋๋จํด! ํ์ง๋ง ๋ธ๋ก์ฒด์ธ ๊ฐ๋ฐ์ ๋์์ด ๋ฐฐ์์ผ ํ ๊ฒ ๋ง์. ๋ค์ ๋จ๊ณ๋ก ๋์๊ฐ๊ธฐ ์ํ ํ์ต ๋ก๋๋งต์ ์ ์ํด์ค๊ฒ.
๐ฏ ์ด๊ธ โ ์ค๊ธ
1. Solidity ์ค๋งํธ ์ปจํธ๋ํธ ๊ฐ๋ฐ
โข Remix IDE๋ก ๊ฐ๋จํ ์ปจํธ๋ํธ ์์ฑ
โข ERC-20, ERC-721 ํ์ค ์ดํด
โข Hardhat ๋๋ Truffle ํ๋ ์์ํฌ ํ์ต
โข ๋จ์ ํ
์คํธ ์์ฑ๋ฒ
2. ๊ณ ๊ธ Web3 ๊ธฐ๋ฅ
โข ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฐ ์ฒ๋ฆฌ
โข ๋ฉํฐ์ฝ(Multicall) ์ต์ ํ
โข ์คํ์ฒด์ธ ์๋ช
ํ์ฉ
โข ENS(Ethereum Name Service) ํตํฉ
3. ํ๋ก ํธ์๋ ํ๋ ์์ํฌ
โข React ๋๋ Vue.js ๋ง์คํฐ
โข Web3Modal, WalletConnect ํตํฉ
โข ์ํ ๊ด๋ฆฌ (Redux, Vuex)
โข TypeScript ์ ์ฉ
๐ ์ค๊ธ โ ๊ณ ๊ธ
1. Layer 2 ์๋ฃจ์
โข Polygon, Arbitrum, Optimism ์ดํด
โข ํฌ๋ก์ค์ฒด์ธ ๋ธ๋ฆฟ์ง ๊ตฌํ
โข Rollup ๊ธฐ์ ํ์ต
2. ๋ํ์ด(DeFi) ํ๋กํ ์ฝ
โข AMM(Automated Market Maker) ์๋ฆฌ
โข ์ ๋์ฑ ํ ๊ด๋ฆฌ
โข ํ๋์ ๋ก (Flash Loan)
โข ์์ต ๋์ฌ(Yield Farming)
3. ๋ณด์ ๋ฐ ๊ฐ์ฌ
โข ์ค๋งํธ ์ปจํธ๋ํธ ์ทจ์ฝ์ ๋ถ์
โข Slither, Mythril ๊ฐ์ ๋ถ์ ๋๊ตฌ
โข ๊ฐ์ฌ ๋ณด๊ณ ์ ์ฝ๊ธฐ
โข ๋ฒ๊ทธ ๋ฐ์ดํฐ ํ๋ก๊ทธ๋จ ์ฐธ์ฌ
4. ๊ณ ๊ธ ์ํคํ
์ฒ
โข ๋ง์ดํฌ๋ก์๋น์ค ์ํคํ
์ฒ
โข ์ด๋ฒคํธ ๊ธฐ๋ฐ ์์คํ
โข ํ(Queue) ์์คํ
(RabbitMQ, Kafka)
โข ๋ถ์ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค
๐ ์ถ์ฒ ํ์ต ๋ฆฌ์์ค
| ์นดํ ๊ณ ๋ฆฌ | ๋ฆฌ์์ค | ์ค๋ช |
|---|---|---|
| ๊ณต์ ๋ฌธ์ | Ethereum.org | ์ด๋๋ฆฌ์ ๊ณต์ ๋ฌธ์, ๊ฐ์ฅ ์ ํํ ์ ๋ณด |
| ํํ ๋ฆฌ์ผ | CryptoZombies | ๊ฒ์์ผ๋ก ๋ฐฐ์ฐ๋ Solidity |
| ๊ฐ์ | Udemy, Coursera | ์ฒด๊ณ์ ์ธ ์จ๋ผ์ธ ๊ฐ์ |
| ์ปค๋ฎค๋ํฐ | Stack Exchange | ์ง๋ฌธ๊ณผ ๋ต๋ณ |
| ๋ด์ค | CoinDesk, The Block | ์ต์ ๋ธ๋ก์ฒด์ธ ๋ด์ค |
| ๊ฐ๋ฐ ๋๊ตฌ | Hardhat, Foundry | ์ค๋งํธ ์ปจํธ๋ํธ ๊ฐ๋ฐ ํ๋ ์์ํฌ |
๐ก ํ์ต ํ
โข ์ด๋ก ๋ง ๊ณต๋ถํ์ง ๋ง๊ณ ์ง์ ๋ง๋ค์ด๋ณด๊ธฐ
โข ์คํ์์ค ํ๋ก์ ํธ ์ฝ๋ ์ฝ๊ธฐ
โข ์ปค๋ฎค๋ํฐ์ ์ ๊ทน์ ์ผ๋ก ์ฐธ์ฌํ๊ธฐ
โข ์ต์ ํธ๋ ๋ ๊ณ์ ํ๋ก์ฐํ๊ธฐ
โข ์์ ํ๋ก์ ํธ๋ถํฐ ์์ํด์ ์ ์ง์ ์ผ๋ก ํ์ฅ
โข ์คํจ๋ฅผ ๋๋ ค์ํ์ง ๋ง๊ธฐ (ํ
์คํธ๋ท ํ์ฉ!)
๐ฌ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ฌ๊ธฐ๊น์ง ์ ๋ง ๊ธด ์ฌ์ ์ด์์ด. ํ์ด์ฌ๊ณผ ํ๋ผ์คํฌ๋ก ๋ธ๋ก์ฒด์ธ ์ง๊ฐ์ ์ฐ๋ํ๋ ์น์ฌ์ดํธ๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ์ ์ฒ์๋ถํฐ ๋๊น์ง ์ดํด๋ดค์ด. ๐
์ฐ๋ฆฌ๊ฐ ํจ๊ป ๋ฐฐ์ด ๋ด์ฉ์ ์ ๋ฆฌํด๋ณด์๋ฉด:
โข ๋ธ๋ก์ฒด์ธ๊ณผ Web3์ ๊ธฐ๋ณธ ๊ฐ๋
โข Flask ๋ฐฑ์๋ ๊ตฌ์ถ ๋ฐ Web3.py ํ์ฉ
โข MetaMask ์ฐ๋ ๋ฐ ์ง๊ฐ ์ธ์ฆ
โข ์ค๋งํธ ์ปจํธ๋ํธ์์ ์ํธ์์ฉ
โข ๋ณด์ ๊ณ ๋ ค์ฌํญ ๋ฐ ์ต์ ํ
โข ์ค์ ํ๋ก์ ํธ ์์ด๋์ด
โข ๋ฌธ์ ํด๊ฒฐ ๋ฐ ๋๋ฒ๊น
๋ฐฉ๋ฒ
๋ธ๋ก์ฒด์ธ ๊ฐ๋ฐ์ ์ฒ์์๋ ์ด๋ ต๊ฒ ๋๊ปด์ง ์ ์์ง๋ง, ํ ๊ฑธ์์ฉ ๋์๊ฐ๋ค ๋ณด๋ฉด ์ ๋ง ์ฌ๋ฏธ์๊ณ ๋ณด๋์ฐฌ ๋ถ์ผ์ผ. ํนํ Web3๋ ์ธํฐ๋ท์ ๋ฏธ๋๋ฅผ ๋ง๋ค์ด๊ฐ๋ ํ์ ์ ์ธ ๊ธฐ์ ์ด๊ฑฐ๋ . ๐
๐ช ์ค์ฒ ๊ณผ์
์ด ๊ธ์ ์ฝ์ ๊ฒ์ผ๋ก ๋๋ด์ง ๋ง๊ณ , ์ง์ ๋ง๋ค์ด๋ณด์!
1. ๊ฐ๋จํ ์ง๊ฐ ์ฐ๋ ํ์ด์ง ๋ง๋ค๊ธฐ
2. ํ
์คํธ๋ท์์ ํ ํฐ ์ ์ก ๊ตฌํํ๊ธฐ
3. ์์ ๋ง์ NFT ์ปฌ๋ ์
๋ง๋ค๊ธฐ
4. ์์ ๋ํ์ด ํ๋กํ ์ฝ ๊ฐ๋ฐํ๊ธฐ
5. ์คํ์์ค ํ๋ก์ ํธ์ ๊ธฐ์ฌํ๊ธฐ
์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์๋ ๋ธ๋ก์ฒด์ธ ๊ธฐ์ ์ ํ์ฉํ ๋ค์ํ ์๋น์ค๋ค์ด ๋ฑ์ฅํ๊ณ ์์ด. ํ์ค์ํ๋ ์ฌ๋ฅ ๊ฑฐ๋, NFT ๊ธฐ๋ฐ ์ธ์ฆ์, ํ ํฐ ๋ฆฌ์๋ ์์คํ ๋ฑ ๊ฐ๋ฅ์ฑ์ ๋ฌด๊ถ๋ฌด์งํด! โจ
ํน์ ๊ฐ๋ฐํ๋ค๊ฐ ๋งํ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด ์ฃผ์ ํ์ง ๋ง๊ณ ์ปค๋ฎค๋ํฐ์ ์ง๋ฌธํ์. ๋ธ๋ก์ฒด์ธ ๊ฐ๋ฐ์ ์ปค๋ฎค๋ํฐ๋ ์ ๋ง ์น์ ํ๊ณ ๋์์ ์ฃผ๋ ค๋ ์ฌ๋๋ค์ด ๋ง์. ๋๋ ์ฒ์์๋ ์๋ฌด๊ฒ๋ ๋ชฐ๋์ง๋ง, ๊ณ์ ๋ฐฐ์ฐ๊ณ ์๋ํ๋ค ๋ณด๋ ์ฌ๊ธฐ๊น์ง ์์ด.
๋ง์ง๋ง์ผ๋ก, ๋ธ๋ก์ฒด์ธ ๊ฐ๋ฐ์ ๋น ๋ฅด๊ฒ ๋ณํํ๋ ๋ถ์ผ์ผ. ์ค๋ ๋ฐฐ์ด ๋ด์ฉ๋ ๋ช ๋ฌ ํ์๋ ๋ ๋์ ๋ฐฉ๋ฒ์ด ๋์ฌ ์ ์์ด. ๊ทธ๋ฌ๋ ํญ์ ๋ฐฐ์ฐ๋ ์์ธ๋ฅผ ์ ์งํ๊ณ , ์๋ก์ด ๊ธฐ์ ์ ์ด๋ฆฐ ๋ง์์ ๊ฐ์ง์! ๐
์, ์ด์ ๋น์ ์ฐจ๋ก์ผ! ํค๋ณด๋๋ฅผ ๋๋๋ฆฌ๊ณ , ์ฝ๋๋ฅผ ์์ฑํ๊ณ , ๋ฉ์ง ๋ธ๋ก์ฒด์ธ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ง๋ค์ด๋ณด์. ๋น์ ์ด ๋ง๋ ์๋น์ค๊ฐ ๋๊ตฐ๊ฐ์ ์ถ์ ๋ณํ์ํฌ ์๋ ์์ด. ํ์ดํ ! ๐ช๐ฅ
Happy Coding! ๐
Build the Future with Blockchain! ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.