Ver3.0 ๐ ๋ผ๋ผ๋ฒจ๋ก ๋ธ๋ก์ฒด์ธ ํฌ์ธํธ ๋ฆฌ์๋ ์์คํ ๊ตฌ์ถํ๊ธฐ: ์ค์ ๊ฐ์ด๋

๐ ๋ผ๋ผ๋ฒจ๋ก ๋ธ๋ก์ฒด์ธ ํฌ์ธํธ ๋ฆฌ์๋ ์์คํ ๊ตฌ์ถํ๊ธฐ: ์ค์ ๊ฐ์ด๋
์น3 ์๋์ ํต์ฌ ๊ธฐ์ , ๋ธ๋ก์ฒด์ธ๊ณผ ๋ผ๋ผ๋ฒจ์ ๋ง๋จ
๐ก ์ด ๊ธ์์ ๋ฐฐ์ธ ๋ด์ฉ
๋ธ๋ก์ฒด์ธ ๊ธฐ์ ๊ณผ ๋ผ๋ผ๋ฒจ ํ๋ ์์ํฌ๋ฅผ ๊ฒฐํฉํด์ ์ค์ ๋ก ์๋ํ๋ ํฌ์ธํธ ๋ฆฌ์๋ ์์คํ ์ ๋ง๋๋ ๋ฐฉ๋ฒ์ ์์๋ณผ ๊ฑฐ์ผ. ์ด๋ก ๋ถํฐ ์ค์ ์ฝ๋๊น์ง, ์น๊ตฌ์๊ฒ ์ค๋ช ํ๋ฏ ์ฝ๊ณ ์ฌ๋ฏธ์๊ฒ ํ์ด๋ณผ๊ฒ! ๐ฏ
๐จ ์ ๋ธ๋ก์ฒด์ธ ํฌ์ธํธ ์์คํ ์ธ๊ฐ?
์์ฆ ์น3, NFT, ๋ฉํ๋ฒ์ค ๊ฐ์ ๋จ์ด๋ค ๋ง์ด ๋ค์ด๋ดค์ง? ์ด ๋ชจ๋ ๊ฒ์ ํต์ฌ์๋ ๋ธ๋ก์ฒด์ธ ๊ธฐ์ ์ด ์์ด. ํนํ ํฌ์ธํธ๋ ๋ฆฌ์๋ ์์คํ ์ ๋ธ๋ก์ฒด์ธ์ผ๋ก ๊ตฌํํ๋ฉด ์์ฒญ๋ ์ฅ์ ๋ค์ด ์๊ฒจ๋๊ฑฐ๋ ! ๐
์ ํต์ ์ธ ํฌ์ธํธ ์์คํ ์ ์ค์ ์๋ฒ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ "ํ๊ธธ๋๋ ํฌ์ธํธ: 1,000์ "์ด๋ผ๊ณ ์ ์ฅ๋์ด ์์ด. ๊ทผ๋ฐ ์ด๊ฒ ์ง์ง ๋ด ํฌ์ธํธ์ผ๊น? ํ์ฌ๊ฐ ๋ง์๋๋ก ์กฐ์ํ ์๋ ์๊ณ , ์๋ฒ๊ฐ ํดํน๋นํ๋ฉด ๋ ์๊ฐ ์๋ ์์ง. ๐ฐ
ํ์ง๋ง ๋ธ๋ก์ฒด์ธ ๊ธฐ๋ฐ ํฌ์ธํธ๋ ๋ฌ๋ผ! ๋ชจ๋ ๊ฑฐ๋ ๋ด์ญ์ด ํฌ๋ช ํ๊ฒ ๊ธฐ๋ก๋๊ณ , ํ ๋ฒ ๊ธฐ๋ก๋๋ฉด ์ ๋ ๋ณ์กฐํ ์ ์์ด. ๊ฒ๋ค๊ฐ ์ฌ๋ฌ ๋ ธ๋์ ๋ถ์ฐ ์ ์ฅ๋๋๊น ์์ ์ฑ๋ ํจ์ฌ ๋์ง. ๐
๐ ๏ธ ํ๋ก์ ํธ ์ค๋น: ํ์ํ ๊ฒ๋ค
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ์์ํด๋ณผ๊น? ๋จผ์ ์ฐ๋ฆฌ๊ฐ ์ค๋นํด์ผ ํ ๊ฒ๋ค์ ์ฒดํฌํด๋ณด์! ๐
โ ํ์ ์ค๋น๋ฌผ
1. ๋ผ๋ผ๋ฒจ ํ๊ฒฝ
- PHP 8.1 ์ด์
- Composer
- Laravel 10.x (์ต์ ๋ฒ์ ๊ถ์ฅ)
- MySQL ๋๋ PostgreSQL
2. ๋ธ๋ก์ฒด์ธ ๊ด๋ จ ๋๊ตฌ
- Web3.php ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- Ethereum ํ
์คํธ๋ท ๊ณ์ (Sepolia ๋๋ Goerli)
- MetaMask ์ง๊ฐ
- Infura ๋๋ Alchemy API ํค
3. ๊ฐ๋ฐ ๋๊ตฌ
- Visual Studio Code ๋๋ PHPStorm
- Postman (API ํ
์คํธ์ฉ)
- Git
์๊ฐ๋ณด๋ค ๋ง์ง? ํ์ง๋ง ๊ฑฑ์ ๋ง! ํ๋์ฉ ์ฐจ๊ทผ์ฐจ๊ทผ ์ค์นํ๊ณ ์ค์ ํ๋ฉด ๋ผ. ํนํ ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ๋ธ๋ก์ฒด์ธ ๊ฐ๋ฐ ๊ด๋ จ ์ฌ๋ฅ์ ๊ฐ์ง ์ ๋ฌธ๊ฐ๋ค์๊ฒ ๋์์ ๋ฐ์ ์๋ ์์ผ๋๊น ๋งํ๋ ๋ถ๋ถ์ด ์์ผ๋ฉด ํ์ฉํด๋ณด๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ! ๐ช
๐ฏ ์์คํ ์ํคํ ์ฒ ์ค๊ณ
์ฝ๋๋ฅผ ์์ฑํ๊ธฐ ์ ์ ์ ์ฒด์ ์ธ ์์คํ ๊ตฌ์กฐ๋ฅผ ๋จผ์ ๊ทธ๋ ค๋ณด๋ ๊ฒ ์ค์ํด. ๊ฑด๋ฌผ์ ์ง์ ๋ ์ค๊ณ๋๊ฐ ํ์ํ ๊ฒ์ฒ๋ผ ๋ง์ด์ผ! ๐๏ธ
์ฐ๋ฆฌ๊ฐ ๋ง๋ค ์์คํ ์ ํฌ๊ฒ ์ธ ๊ฐ์ง ๋ ์ด์ด๋ก ๊ตฌ์ฑ๋ ๊ฑฐ์ผ:
๐ท ๋ ์ด์ด ๊ตฌ์กฐ
1. ํ๋ก ํธ์๋ ๋ ์ด์ด
์ฌ์ฉ์๊ฐ ์ง์ ๋ณด๊ณ ์ํธ์์ฉํ๋ ๋ถ๋ถ. Vue.js๋ React๋ฅผ ์ฌ์ฉํ ์๋ ์๊ณ , ๋ผ๋ผ๋ฒจ์ Blade ํ
ํ๋ฆฟ๋ง์ผ๋ก๋ ์ถฉ๋ถํด.
2. ๋ฐฑ์๋ ๋ ์ด์ด (๋ผ๋ผ๋ฒจ)
๋น์ฆ๋์ค ๋ก์ง์ ์ฒ๋ฆฌํ๋ ํต์ฌ ๋ถ๋ถ. ์ฌ์ฉ์ ์ธ์ฆ, ํฌ์ธํธ ๊ณ์ฐ, ํธ๋์ญ์
๊ฒ์ฆ ๋ฑ์ ๋ด๋นํด.
3. ๋ธ๋ก์ฒด์ธ ๋ ์ด์ด
์ค์ ํฌ์ธํธ๊ฐ ํ ํฐ์ผ๋ก ๋ฐํ๋๊ณ ๊ฑฐ๋๋๋ ๊ณณ. ์ด๋๋ฆฌ์ ๊ธฐ๋ฐ์ ์ค๋งํธ ์ปจํธ๋ํธ๋ฅผ ์ฌ์ฉํ ๊ฑฐ์ผ.
๐ ๋ผ๋ผ๋ฒจ ํ๋ก์ ํธ ์ด๊ธฐ ์ค์
์, ์ด์ ์ค์ ๋ก ์ฝ๋๋ฅผ ์์ฑํด๋ณผ ์๊ฐ์ด์ผ! ๋จผ์ ๋ผ๋ผ๋ฒจ ํ๋ก์ ํธ๋ฅผ ์์ฑํ๊ณ ๊ธฐ๋ณธ ์ค์ ์ ํด๋ณด์. ๐
Step 1: ๋ผ๋ผ๋ฒจ ํ๋ก์ ํธ ์์ฑ
composer create-project laravel/laravel blockchain-reward-system
cd blockchain-reward-system
php artisan serve
ํ๋ก์ ํธ๊ฐ ์์ฑ๋๋ฉด http://localhost:8000์์ ๋ผ๋ผ๋ฒจ ์ฐ์ปด ํ์ด์ง๋ฅผ ๋ณผ ์ ์์ด. ์ฌ๊ธฐ๊น์ง ์๋ค๋ฉด ์ฒซ ๋ฒ์งธ ๊ด๋ฌธ ํต๊ณผ! ๐
Step 2: ํ์ํ ํจํค์ง ์ค์น
composer require web3p/web3.php
composer require simplito/elliptic-php
composer require kornrunner/keccak
์ด ํจํค์ง๋ค์ ๋ธ๋ก์ฒด์ธ๊ณผ ํต์ ํ๊ณ ์ํธํ ์์ ์ ์ํํ๋ ๋ฐ ํ์ํ ํต์ฌ ๋๊ตฌ๋ค์ด์ผ. web3.php๋ ์ด๋๋ฆฌ์ ๋คํธ์ํฌ์ ์ํธ์์ฉํ ์ ์๊ฒ ํด์ฃผ๋ PHP ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ง. ๐
๐ง ๋ฐ์ดํฐ๋ฒ ์ด์ค ์คํค๋ง ์ค๊ณ
๋ธ๋ก์ฒด์ธ์ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ฉด ์ข๊ฒ ์ง๋ง, ๊ฐ์ค๋น(์์๋ฃ)๊ฐ ์์ฒญ๋๊ฒ ๋น์ธ! ๊ทธ๋์ ์ฐ๋ฆฌ๋ ํ์ด๋ธ๋ฆฌ๋ ๋ฐฉ์์ ์ฌ์ฉํ ๊ฑฐ์ผ. ์ค์ํ ๊ฑฐ๋ ๋ด์ญ์ ๋ธ๋ก์ฒด์ธ์, ๋๋จธ์ง ๋ถ๊ฐ ์ ๋ณด๋ ์ผ๋ฐ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅํ๋ ๊ฑฐ์ง. ๐ก
Step 3: ๋ง์ด๊ทธ๋ ์ด์ ํ์ผ ์์ฑ
php artisan make:migration create_users_wallets_table
php artisan make:migration create_point_transactions_table
php artisan make:migration create_blockchain_logs_table
์ด์ ๊ฐ ๋ง์ด๊ทธ๋ ์ด์ ํ์ผ์ ์์ฑํด๋ณด์. ๋จผ์ ์ฌ์ฉ์ ์ง๊ฐ ํ ์ด๋ธ๋ถํฐ! ๐
users_wallets ํ ์ด๋ธ
public function up()
{
Schema::create('users_wallets', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('wallet_address', 42)->unique();
$table->string('encrypted_private_key')->nullable();
$table->decimal('balance', 20, 8)->default(0);
$table->boolean('is_verified')->default(false);
$table->timestamp('last_sync_at')->nullable();
$table->timestamps();
$table->index('wallet_address');
$table->index('user_id');
});
}
์ฌ๊ธฐ์ ์ค์ํ ํฌ์ธํธ! wallet_address๋ 42์๋ฆฌ์ธ๋ฐ, ์ด๋๋ฆฌ์ ์ฃผ์๊ฐ "0x"๋ก ์์ํ๋ 40์๋ฆฌ 16์ง์์ด๊ธฐ ๋๋ฌธ์ด์ผ. encrypted_private_key๋ ๋ณด์์ ์ํด ์ํธํํด์ ์ ์ฅํ๊ณ , ์ค์ ์๋น์ค์์๋ ๋ ์์ ํ ๋ฐฉ๋ฒ(HSM, KMS ๋ฑ)์ ์ฌ์ฉํ๋ ๊ฒ ์ข์. ๐
point_transactions ํ ์ด๋ธ
public function up()
{
Schema::create('point_transactions', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->enum('type', ['earn', 'spend', 'transfer', 'reward']);
$table->decimal('amount', 20, 8);
$table->string('description')->nullable();
$table->string('reference_type')->nullable();
$table->unsignedBigInteger('reference_id')->nullable();
$table->string('transaction_hash', 66)->nullable();
$table->enum('status', ['pending', 'confirmed', 'failed'])->default('pending');
$table->integer('confirmations')->default(0);
$table->timestamp('confirmed_at')->nullable();
$table->timestamps();
$table->index(['user_id', 'created_at']);
$table->index('transaction_hash');
$table->index('status');
});
}
์ด ํ ์ด๋ธ์ ๋ชจ๋ ํฌ์ธํธ ๊ฑฐ๋๋ฅผ ์ถ์ ํด. transaction_hash๋ ๋ธ๋ก์ฒด์ธ์ ์ค์ ํธ๋์ญ์ ํด์๋ฅผ ์ ์ฅํ๋ ํ๋์ผ. 66์๋ฆฌ์ธ ์ด์ ๋ "0x" + 64์๋ฆฌ 16์ง์์ด๊ธฐ ๋๋ฌธ์ด์ง! ๐ฏ
blockchain_logs ํ ์ด๋ธ
public function up()
{
Schema::create('blockchain_logs', function (Blueprint $table) {
$table->id();
$table->string('transaction_hash', 66)->unique();
$table->string('from_address', 42);
$table->string('to_address', 42);
$table->decimal('amount', 20, 8);
$table->unsignedBigInteger('block_number')->nullable();
$table->integer('gas_used')->nullable();
$table->decimal('gas_price', 20, 0)->nullable();
$table->text('raw_data')->nullable();
$table->enum('status', ['pending', 'success', 'failed']);
$table->timestamps();
$table->index('transaction_hash');
$table->index(['from_address', 'to_address']);
});
}
๋ธ๋ก์ฒด์ธ ๋ก๊ทธ ํ ์ด๋ธ์ ์จ์ฒด์ธ ๋ฐ์ดํฐ๋ฅผ ์คํ์ฒด์ธ์ ๋ฐฑ์ ํ๋ ์ฉ๋์ผ. ๋์ค์ ํต๊ณ๋ ๋ถ์ํ ๋ ๋ธ๋ก์ฒด์ธ์ ์ง์ ์กฐํํ๋ ๊ฒ๋ณด๋ค ํจ์ฌ ๋น ๋ฅด๊ฑฐ๋ ! โก
๐จ ์ค๋งํธ ์ปจํธ๋ํธ ์์ฑ
์ด์ ๋ธ๋ก์ฒด์ธ์ ํต์ฌ์ธ ์ค๋งํธ ์ปจํธ๋ํธ๋ฅผ ์์ฑํด๋ณผ ์ฐจ๋ก์ผ! Solidity ์ธ์ด๋ฅผ ์ฌ์ฉํ ๊ฑด๋ฐ, ์ฒ์ ๋ณด๋ฉด ์ข ๋ฏ์ค ์ ์์ง๋ง JavaScript๋ ๋น์ทํ ๋ถ๋ถ์ด ๋ง์์ ๊ธ๋ฐฉ ์ต์ํด์ง ๊ฑฐ์ผ. ๐
๐ก ์ค๋งํธ ์ปจํธ๋ํธ๋? ๋ธ๋ก์ฒด์ธ ์์์ ์๋์ผ๋ก ์คํ๋๋ ํ๋ก๊ทธ๋จ์ด์ผ. ํ ๋ฒ ๋ฐฐํฌ๋๋ฉด ๋๊ตฌ๋ ์์ ํ ์ ์๊ณ , ์ฝ๋์ ์์ฑ๋ ๋๋ก๋ง ์๋ํด. ๋ง์น ์๋ํ๋งค๊ธฐ์ฒ๋ผ ๋ง์ด์ผ! ๋์ ๋ฃ์ผ๋ฉด ์๋์ผ๋ก ์๋ฃ์๊ฐ ๋์ค๋ ๊ฒ์ฒ๋ผ, ์กฐ๊ฑด์ด ์ถฉ์กฑ๋๋ฉด ์๋์ผ๋ก ํฌ์ธํธ๊ฐ ์ ์ก๋๋ ๊ฑฐ์ง.
ํ๋ก์ ํธ ๋ฃจํธ์ contracts ํด๋๋ฅผ ๋ง๋ค๊ณ RewardToken.sol ํ์ผ์ ์์ฑํ์:
RewardToken.sol - ERC20 ๊ธฐ๋ฐ ๋ฆฌ์๋ ํ ํฐ
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
contract RewardToken is ERC20, Ownable, Pausable {
// ํฌ์ธํธ ์ ๋ฆฝ ์ด๋ฒคํธ
event PointsEarned(address indexed user, uint256 amount, string reason);
// ํฌ์ธํธ ์ฌ์ฉ ์ด๋ฒคํธ
event PointsSpent(address indexed user, uint256 amount, string reason);
// ํฌ์ธํธ ์ ์ก ์ด๋ฒคํธ
event PointsTransferred(address indexed from, address indexed to, uint256 amount);
// ์ต๋ ๋ฐํ๋ (10์ต ํ ํฐ)
uint256 public constant MAX_SUPPLY = 1000000000 * 10**18;
// ์ฌ์ฉ์๋ณ ์ผ์ผ ์ ๋ฆฝ ํ๋
mapping(address => uint256) public dailyEarnLimit;
mapping(address => uint256) public lastEarnDate;
mapping(address => uint256) public todayEarned;
// ๊ธฐ๋ณธ ์ผ์ผ ํ๋ (10,000 ํฌ์ธํธ)
uint256 public defaultDailyLimit = 10000 * 10**18;
constructor() ERC20("RewardPoint", "RWP") {
// ์ด๊ธฐ ๋ฐํ๋ (1์ต ํ ํฐ)
_mint(msg.sender, 100000000 * 10**18);
}
// ํฌ์ธํธ ์ ๋ฆฝ ํจ์
function earnPoints(address user, uint256 amount, string memory reason)
external
onlyOwner
whenNotPaused
{
require(user != address(0), "Invalid address");
require(amount > 0, "Amount must be positive");
require(totalSupply() + amount <= MAX_SUPPLY, "Exceeds max supply");
// ์ผ์ผ ํ๋ ์ฒดํฌ
uint256 userLimit = dailyEarnLimit[user] > 0 ? dailyEarnLimit[user] : defaultDailyLimit;
if (block.timestamp / 1 days > lastEarnDate[user] / 1 days) {
todayEarned[user] = 0;
lastEarnDate[user] = block.timestamp;
}
require(todayEarned[user] + amount <= userLimit, "Daily limit exceeded");
todayEarned[user] += amount;
_mint(user, amount);
emit PointsEarned(user, amount, reason);
}
// ํฌ์ธํธ ์ฌ์ฉ ํจ์
function spendPoints(address user, uint256 amount, string memory reason)
external
onlyOwner
whenNotPaused
{
require(user != address(0), "Invalid address");
require(amount > 0, "Amount must be positive");
require(balanceOf(user) >= amount, "Insufficient balance");
_burn(user, amount);
emit PointsSpent(user, amount, reason);
}
// ์ฌ์ฉ์๋ณ ์ผ์ผ ํ๋ ์ค์
function setUserDailyLimit(address user, uint256 limit) external onlyOwner {
dailyEarnLimit[user] = limit;
}
// ๊ธฐ๋ณธ ์ผ์ผ ํ๋ ์ค์
function setDefaultDailyLimit(uint256 limit) external onlyOwner {
defaultDailyLimit = limit;
}
// ๊ธด๊ธ ์ ์ง
function pause() external onlyOwner {
_pause();
}
// ์ฌ๊ฐ
function unpause() external onlyOwner {
_unpause();
}
// ์ ์ก ์ค๋ฒ๋ผ์ด๋ (์ด๋ฒคํธ ์ถ๊ฐ)
function transfer(address to, uint256 amount)
public
override
whenNotPaused
returns (bool)
{
bool success = super.transfer(to, amount);
if (success) {
emit PointsTransferred(msg.sender, to, amount);
}
return success;
}
}
์! ์ฝ๋๊ฐ ์ข ๊ธธ์ง? ํ๋์ฉ ๋ฏ์ด๋ณด๋ฉด ๊ทธ๋ ๊ฒ ์ด๋ ต์ง ์์. ํต์ฌ ๊ธฐ๋ฅ๋ค์ ์ดํด๋ณด์: ๐
| ๊ธฐ๋ฅ | ์ค๋ช | ๋ณด์ ์์ |
|---|---|---|
| earnPoints | ์ฌ์ฉ์์๊ฒ ํฌ์ธํธ ์ ๋ฆฝ | ์ผ์ผ ํ๋ ์ฒดํฌ, ์ต๋ ๋ฐํ๋ ์ ํ |
| spendPoints | ํฌ์ธํธ ์ฌ์ฉ ๋ฐ ์๊ฐ | ์์ก ํ์ธ, ๊ถํ ์ฒดํฌ |
| pause/unpause | ๊ธด๊ธ ์ํฉ ์ ์์คํ ์ ์ง | ๊ด๋ฆฌ์ ์ ์ฉ, ๋ณด์ ์ฌ๊ณ ๋์ |
| dailyLimit | ์ผ์ผ ์ ๋ฆฝ ํ๋ ๊ด๋ฆฌ | ์ด๋ทฐ์ง ๋ฐฉ์ง, ์ธํ๋ ์ด์ ์ ์ด |
ํนํ ์ผ์ผ ํ๋ ์์คํ ์ ์ ๋ง ์ค์ํด! ๋๊ตฐ๊ฐ ์์คํ ์ ์ ์ฉํด์ ๋ฌดํ์ ํฌ์ธํธ๋ฅผ ์ ๋ฆฝํ๋ ๊ฑธ ๋ง์์ฃผ๊ฑฐ๋ . ์ค์ ์๋น์ค์์๋ ์ด๋ฐ ๋ณด์ ์ฅ์น๋ค์ด ํ์์ผ. ๐ก๏ธ
๐ ๋ผ๋ผ๋ฒจ๊ณผ ๋ธ๋ก์ฒด์ธ ์ฐ๋
์ค๋งํธ ์ปจํธ๋ํธ๋ฅผ ์์ฑํ์ผ๋ ์ด์ ๋ผ๋ผ๋ฒจ์์ ์ด๊ฑธ ์ฌ์ฉํ ์ฐจ๋ก์ผ! Web3.php ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ์ฉํด์ ๋ธ๋ก์ฒด์ธ๊ณผ ํต์ ํ๋ ์๋น์ค ํด๋์ค๋ฅผ ๋ง๋ค์ด๋ณด์. ๐
Step 4: BlockchainService ํด๋์ค ์์ฑ
php artisan make:service BlockchainService
app/Services/BlockchainService.php ํ์ผ์ ์ด๊ณ ๋ค์ ์ฝ๋๋ฅผ ์์ฑํด:
<?php
namespace App\Services;
use Web3\Web3;
use Web3\Contract;
use Web3\Utils;
use Illuminate\Support\Facades\Log;
use Exception;
class BlockchainService
{
protected $web3;
protected $contract;
protected $contractAddress;
protected $ownerAddress;
protected $ownerPrivateKey;
public function __construct()
{
// Infura ๋๋ Alchemy RPC URL
$rpcUrl = config('blockchain.rpc_url');
$this->web3 = new Web3($rpcUrl);
// ์ปจํธ๋ํธ ์ค์
$this->contractAddress = config('blockchain.contract_address');
$contractAbi = json_decode(file_get_contents(storage_path('app/contract_abi.json')), true);
$this->contract = new Contract($rpcUrl, $contractAbi);
$this->contract->at($this->contractAddress);
// ๊ด๋ฆฌ์ ์ง๊ฐ ์ค์
$this->ownerAddress = config('blockchain.owner_address');
$this->ownerPrivateKey = config('blockchain.owner_private_key');
}
/**
* ์ฌ์ฉ์์๊ฒ ํฌ์ธํธ ์ ๋ฆฝ
*/
public function earnPoints($userAddress, $amount, $reason = 'Activity reward')
{
try {
// Wei ๋จ์๋ก ๋ณํ (1 ํ ํฐ = 10^18 Wei)
$amountInWei = Utils::toWei($amount, 'ether');
// ํธ๋์ญ์
๋ฐ์ดํฐ ์์ฑ
$data = $this->contract->getData('earnPoints', $userAddress, $amountInWei, $reason);
// ๊ฐ์ค ์ถ์
$gasEstimate = $this->estimateGas($this->ownerAddress, $this->contractAddress, $data);
// ํธ๋์ญ์
์ ์ก
$txHash = $this->sendTransaction([
'from' => $this->ownerAddress,
'to' => $this->contractAddress,
'gas' => dechex($gasEstimate * 1.2), // 20% ์ฌ์
'data' => $data
]);
Log::info('Points earned', [
'user' => $userAddress,
'amount' => $amount,
'tx_hash' => $txHash
]);
return [
'success' => true,
'transaction_hash' => $txHash,
'amount' => $amount
];
} catch (Exception $e) {
Log::error('Failed to earn points', [
'error' => $e->getMessage(),
'user' => $userAddress
]);
return [
'success' => false,
'error' => $e->getMessage()
];
}
}
/**
* ํฌ์ธํธ ์ฌ์ฉ
*/
public function spendPoints($userAddress, $amount, $reason = 'Purchase')
{
try {
$amountInWei = Utils::toWei($amount, 'ether');
$data = $this->contract->getData('spendPoints', $userAddress, $amountInWei, $reason);
$gasEstimate = $this->estimateGas($this->ownerAddress, $this->contractAddress, $data);
$txHash = $this->sendTransaction([
'from' => $this->ownerAddress,
'to' => $this->contractAddress,
'gas' => dechex($gasEstimate * 1.2),
'data' => $data
]);
return [
'success' => true,
'transaction_hash' => $txHash,
'amount' => $amount
];
} catch (Exception $e) {
Log::error('Failed to spend points', [
'error' => $e->getMessage(),
'user' => $userAddress
]);
return [
'success' => false,
'error' => $e->getMessage()
];
}
}
/**
* ์์ก ์กฐํ
*/
public function getBalance($address)
{
try {
$balance = null;
$this->contract->call('balanceOf', $address, function ($err, $result) use (&$balance) {
if ($err !== null) {
throw new Exception($err->getMessage());
}
$balance = $result[0]->toString();
});
// Wei์์ Ether๋ก ๋ณํ
$balanceInEther = Utils::fromWei($balance, 'ether');
return [
'success' => true,
'balance' => $balanceInEther
];
} catch (Exception $e) {
return [
'success' => false,
'error' => $e->getMessage()
];
}
}
/**
* ํธ๋์ญ์
์ํ ํ์ธ
*/
public function getTransactionStatus($txHash)
{
try {
$receipt = null;
$this->web3->eth->getTransactionReceipt($txHash, function ($err, $result) use (&$receipt) {
if ($err !== null) {
throw new Exception($err->getMessage());
}
$receipt = $result;
});
if ($receipt === null) {
return [
'status' => 'pending',
'confirmations' => 0
];
}
$currentBlock = $this->getCurrentBlockNumber();
$confirmations = $currentBlock - hexdec($receipt->blockNumber);
return [
'status' => $receipt->status === '0x1' ? 'success' : 'failed',
'confirmations' => $confirmations,
'block_number' => hexdec($receipt->blockNumber),
'gas_used' => hexdec($receipt->gasUsed)
];
} catch (Exception $e) {
return [
'status' => 'error',
'error' => $e->getMessage()
];
}
}
/**
* ๊ฐ์ค ์ถ์
*/
protected function estimateGas($from, $to, $data)
{
$gas = null;
$this->web3->eth->estimateGas([
'from' => $from,
'to' => $to,
'data' => $data
], function ($err, $result) use (&$gas) {
if ($err !== null) {
throw new Exception($err->getMessage());
}
$gas = hexdec($result);
});
return $gas;
}
/**
* ํธ๋์ญ์
์ ์ก
*/
protected function sendTransaction($params)
{
// ์ค์ ๊ตฌํ์์๋ private key๋ก ์๋ช
ํ ์ ์ก
// ๋ณด์์ ์ํด ์ค์ ์๋น์ค์์๋ ๋ณ๋์ ์๋ช
์๋น์ค ์ฌ์ฉ ๊ถ์ฅ
$txHash = null;
// ์ฌ๊ธฐ์๋ ๊ฐ๋จํ ํํ
// ์ค์ ๋ก๋ eth_sendRawTransaction ์ฌ์ฉ
return $txHash;
}
/**
* ํ์ฌ ๋ธ๋ก ๋ฒํธ ์กฐํ
*/
protected function getCurrentBlockNumber()
{
$blockNumber = null;
$this->web3->eth->blockNumber(function ($err, $result) use (&$blockNumber) {
if ($err !== null) {
throw new Exception($err->getMessage());
}
$blockNumber = hexdec($result);
});
return $blockNumber;
}
}
์ด ์๋น์ค ํด๋์ค๊ฐ ๋ผ๋ผ๋ฒจ๊ณผ ๋ธ๋ก์ฒด์ธ์ ์ฐ๊ฒฐํ๋ ๋ค๋ฆฌ ์ญํ ์ ํด! ์ฃผ์ ๋ฉ์๋๋ค์ ์ดํด๋ณด๋ฉด: ๐
๐ ํต์ฌ ๋ฉ์๋
earnPoints() - ํฌ์ธํธ ์ ๋ฆฝ
์ฌ์ฉ์ ์ฃผ์์ ๊ธ์ก์ ๋ฐ์์ ์ค๋งํธ ์ปจํธ๋ํธ์ earnPoints ํจ์๋ฅผ ํธ์ถํด. ํธ๋์ญ์
์ด ์ฑ๊ณตํ๋ฉด ํด์๊ฐ์ ๋ฐํํ์ง.
spendPoints() - ํฌ์ธํธ ์ฌ์ฉ
ํฌ์ธํธ๋ฅผ ์๊ฐ(burn)ํ๋ ํจ์์ผ. ์ฌ์ฉ์๊ฐ ํฌ์ธํธ๋ก ๋ญ๊ฐ๋ฅผ ๊ตฌ๋งคํ ๋ ํธ์ถ๋ผ.
getBalance() - ์์ก ์กฐํ
๋ธ๋ก์ฒด์ธ์์ ์ค์๊ฐ์ผ๋ก ์ฌ์ฉ์์ ํฌ์ธํธ ์์ก์ ๊ฐ์ ธ์.
getTransactionStatus() - ํธ๋์ญ์
์ํ ํ์ธ
ํธ๋์ญ์
์ด ๋ธ๋ก์ ํฌํจ๋์๋์ง, ๋ช ๊ฐ์ ์ปจํ์ ๋ฐ์๋์ง ํ์ธํด.
๐ฎ ์ปจํธ๋กค๋ฌ์ API ์๋ํฌ์ธํธ ๊ตฌํ
์ด์ ์ฌ์ฉ์๊ฐ ์ค์ ๋ก ์ฌ์ฉํ API๋ฅผ ๋ง๋ค์ด๋ณด์! RESTful API ํํ๋ก ๊น๋ํ๊ฒ ๊ตฌ์ฑํ ๊ฑฐ์ผ. ๐ก
Step 5: ์ปจํธ๋กค๋ฌ ์์ฑ
php artisan make:controller Api/RewardController
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Services\BlockchainService;
use App\Models\UserWallet;
use App\Models\PointTransaction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
class RewardController extends Controller
{
protected $blockchain;
public function __construct(BlockchainService $blockchain)
{
$this->blockchain = $blockchain;
}
/**
* ํฌ์ธํธ ์์ก ์กฐํ
*/
public function getBalance(Request $request)
{
$user = Auth::user();
$wallet = UserWallet::where('user_id', $user->id)->first();
if (!$wallet) {
return response()->json([
'success' => false,
'message' => 'Wallet not found'
], 404);
}
// ๋ธ๋ก์ฒด์ธ์์ ์ค์๊ฐ ์์ก ์กฐํ
$result = $this->blockchain->getBalance($wallet->wallet_address);
if ($result['success']) {
// DB ์์ก ๋๊ธฐํ
$wallet->update([
'balance' => $result['balance'],
'last_sync_at' => now()
]);
return response()->json([
'success' => true,
'balance' => $result['balance'],
'wallet_address' => $wallet->wallet_address
]);
}
return response()->json([
'success' => false,
'message' => 'Failed to fetch balance'
], 500);
}
/**
* ํฌ์ธํธ ์ ๋ฆฝ
*/
public function earnPoints(Request $request)
{
$validator = Validator::make($request->all(), [
'user_id' => 'required|exists:users,id',
'amount' => 'required|numeric|min:0.01',
'reason' => 'required|string|max:255',
'reference_type' => 'nullable|string',
'reference_id' => 'nullable|integer'
]);
if ($validator->fails()) {
return response()->json([
'success' => false,
'errors' => $validator->errors()
], 422);
}
$wallet = UserWallet::where('user_id', $request->user_id)->first();
if (!$wallet) {
return response()->json([
'success' => false,
'message' => 'User wallet not found'
], 404);
}
DB::beginTransaction();
try {
// ํธ๋์ญ์
๋ ์ฝ๋ ์์ฑ (pending ์ํ)
$transaction = PointTransaction::create([
'user_id' => $request->user_id,
'type' => 'earn',
'amount' => $request->amount,
'description' => $request->reason,
'reference_type' => $request->reference_type,
'reference_id' => $request->reference_id,
'status' => 'pending'
]);
// ๋ธ๋ก์ฒด์ธ์ ํฌ์ธํธ ์ ๋ฆฝ
$result = $this->blockchain->earnPoints(
$wallet->wallet_address,
$request->amount,
$request->reason
);
if ($result['success']) {
// ํธ๋์ญ์
ํด์ ์
๋ฐ์ดํธ
$transaction->update([
'transaction_hash' => $result['transaction_hash']
]);
DB::commit();
// ๋น๋๊ธฐ๋ก ํธ๋์ญ์
์ํ ๋ชจ๋ํฐ๋ง ์์
dispatch(new \App\Jobs\MonitorTransaction($transaction->id));
return response()->json([
'success' => true,
'message' => 'Points earned successfully',
'transaction_id' => $transaction->id,
'transaction_hash' => $result['transaction_hash'],
'amount' => $request->amount
]);
} else {
DB::rollBack();
$transaction->update([
'status' => 'failed'
]);
return response()->json([
'success' => false,
'message' => 'Failed to earn points',
'error' => $result['error']
], 500);
}
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'success' => false,
'message' => 'An error occurred',
'error' => $e->getMessage()
], 500);
}
}
/**
* ํฌ์ธํธ ์ฌ์ฉ
*/
public function spendPoints(Request $request)
{
$validator = Validator::make($request->all(), [
'amount' => 'required|numeric|min:0.01',
'reason' => 'required|string|max:255',
'reference_type' => 'nullable|string',
'reference_id' => 'nullable|integer'
]);
if ($validator->fails()) {
return response()->json([
'success' => false,
'errors' => $validator->errors()
], 422);
}
$user = Auth::user();
$wallet = UserWallet::where('user_id', $user->id)->first();
if (!$wallet) {
return response()->json([
'success' => false,
'message' => 'Wallet not found'
], 404);
}
// ์์ก ํ์ธ
if ($wallet->balance < $request->amount) {
return response()->json([
'success' => false,
'message' => 'Insufficient balance'
], 400);
}
DB::beginTransaction();
try {
$transaction = PointTransaction::create([
'user_id' => $user->id,
'type' => 'spend',
'amount' => $request->amount,
'description' => $request->reason,
'reference_type' => $request->reference_type,
'reference_id' => $request->reference_id,
'status' => 'pending'
]);
$result = $this->blockchain->spendPoints(
$wallet->wallet_address,
$request->amount,
$request->reason
);
if ($result['success']) {
$transaction->update([
'transaction_hash' => $result['transaction_hash']
]);
// ๋๊ด์ ์
๋ฐ์ดํธ (์ค์ ์ปจํ ์ ์ ์์ก ์ฐจ๊ฐ)
$wallet->decrement('balance', $request->amount);
DB::commit();
dispatch(new \App\Jobs\MonitorTransaction($transaction->id));
return response()->json([
'success' => true,
'message' => 'Points spent successfully',
'transaction_id' => $transaction->id,
'remaining_balance' => $wallet->balance
]);
} else {
DB::rollBack();
return response()->json([
'success' => false,
'message' => 'Failed to spend points',
'error' => $result['error']
], 500);
}
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'success' => false,
'message' => 'An error occurred',
'error' => $e->getMessage()
], 500);
}
}
/**
* ๊ฑฐ๋ ๋ด์ญ ์กฐํ
*/
public function getTransactions(Request $request)
{
$user = Auth::user();
$transactions = PointTransaction::where('user_id', $user->id)
->orderBy('created_at', 'desc')
->paginate(20);
return response()->json([
'success' => true,
'transactions' => $transactions
]);
}
/**
* ํน์ ํธ๋์ญ์
์ํ ์กฐํ
*/
public function getTransactionStatus($id)
{
$user = Auth::user();
$transaction = PointTransaction::where('id', $id)
->where('user_id', $user->id)
->first();
if (!$transaction) {
return response()->json([
'success' => false,
'message' => 'Transaction not found'
], 404);
}
// ๋ธ๋ก์ฒด์ธ์์ ์ต์ ์ํ ์กฐํ
if ($transaction->transaction_hash) {
$status = $this->blockchain->getTransactionStatus($transaction->transaction_hash);
// DB ์
๋ฐ์ดํธ
if ($status['status'] === 'success' && $transaction->status !== 'confirmed') {
$transaction->update([
'status' => 'confirmed',
'confirmations' => $status['confirmations'],
'confirmed_at' => now()
]);
}
}
return response()->json([
'success' => true,
'transaction' => $transaction
]);
}
}
API ์ปจํธ๋กค๋ฌ๊ฐ ์์ฑ๋์ด! ์ด์ ๋ผ์ฐํธ๋ฅผ ์ค์ ํด๋ณด์. routes/api.php ํ์ผ์ ์ด์ด์: ๐ฃ๏ธ
use App\Http\Controllers\Api\RewardController;
Route::middleware('auth:sanctum')->group(function () {
// ํฌ์ธํธ ๊ด๋ จ API
Route::prefix('rewards')->group(function () {
Route::get('/balance', [RewardController::class, 'getBalance']);
Route::post('/earn', [RewardController::class, 'earnPoints']);
Route::post('/spend', [RewardController::class, 'spendPoints']);
Route::get('/transactions', [RewardController::class, 'getTransactions']);
Route::get('/transactions/{id}', [RewardController::class, 'getTransactionStatus']);
});
});
โ๏ธ ๋ฐฑ๊ทธ๋ผ์ด๋ ์์ : ํธ๋์ญ์ ๋ชจ๋ํฐ๋ง
๋ธ๋ก์ฒด์ธ ํธ๋์ญ์ ์ ์ฆ์ ์๋ฃ๋์ง ์์. ๋ธ๋ก์ ํฌํจ๋๊ณ ์ฌ๋ฌ ๊ฐ์ ์ปจํ์ ๋ฐ์์ผ ํ๊ฑฐ๋ . ๊ทธ๋์ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ๊ณ์ ์ํ๋ฅผ ์ฒดํฌํ๋ Job์ ๋ง๋ค์ด์ผ ํด! ๐
Step 6: Job ์์ฑ
php artisan make:job MonitorTransaction
<?php
namespace App\Jobs;
use App\Models\PointTransaction;
use App\Models\BlockchainLog;
use App\Services\BlockchainService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class MonitorTransaction implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $transactionId;
public $tries = 20; // ์ต๋ 20๋ฒ ์ฌ์๋
public $backoff = 30; // 30์ด ๊ฐ๊ฒฉ
public function __construct($transactionId)
{
$this->transactionId = $transactionId;
}
public function handle(BlockchainService $blockchain)
{
$transaction = PointTransaction::find($this->transactionId);
if (!$transaction || !$transaction->transaction_hash) {
Log::warning('Transaction not found or no hash', ['id' => $this->transactionId]);
return;
}
// ์ด๋ฏธ ํ์ ๋ ํธ๋์ญ์
์ ์คํต
if ($transaction->status === 'confirmed') {
return;
}
// ๋ธ๋ก์ฒด์ธ์์ ์ํ ์กฐํ
$status = $blockchain->getTransactionStatus($transaction->transaction_hash);
if ($status['status'] === 'pending') {
// ์์ง pending์ด๋ฉด ๋ค์ ํ์ ๋ฃ๊ธฐ
$this->release(30);
return;
}
if ($status['status'] === 'success') {
// ์ถฉ๋ถํ ์ปจํ์ ๋ฐ์๋์ง ํ์ธ (๋ณดํต 12๊ฐ ์ด์)
if ($status['confirmations'] >= 12) {
$transaction->update([
'status' => 'confirmed',
'confirmations' => $status['confirmations'],
'confirmed_at' => now()
]);
// ๋ธ๋ก์ฒด์ธ ๋ก๊ทธ ์ ์ฅ
BlockchainLog::create([
'transaction_hash' => $transaction->transaction_hash,
'from_address' => config('blockchain.owner_address'),
'to_address' => $transaction->user->wallet->wallet_address,
'amount' => $transaction->amount,
'block_number' => $status['block_number'],
'gas_used' => $status['gas_used'],
'status' => 'success'
]);
// ์ฌ์ฉ์์๊ฒ ์๋ฆผ ์ ์ก
$transaction->user->notify(new \App\Notifications\PointsConfirmed($transaction));
Log::info('Transaction confirmed', [
'id' => $transaction->id,
'hash' => $transaction->transaction_hash,
'confirmations' => $status['confirmations']
]);
} else {
// ์ปจํ์ด ๋ถ์กฑํ๋ฉด ๋ค์ ์ฒดํฌ
$this->release(30);
}
} elseif ($status['status'] === 'failed') {
// ํธ๋์ญ์
์คํจ
$transaction->update([
'status' => 'failed'
]);
// ์คํจ ์ ๋กค๋ฐฑ ์ฒ๋ฆฌ
if ($transaction->type === 'spend') {
// ์ฐจ๊ฐํ๋ ํฌ์ธํธ ๋ณต๊ตฌ
$transaction->user->wallet->increment('balance', $transaction->amount);
}
Log::error('Transaction failed', [
'id' => $transaction->id,
'hash' => $transaction->transaction_hash
]);
// ์ฌ์ฉ์์๊ฒ ์คํจ ์๋ฆผ
$transaction->user->notify(new \App\Notifications\TransactionFailed($transaction));
}
}
public function failed(\Throwable $exception)
{
Log::error('MonitorTransaction job failed', [
'transaction_id' => $this->transactionId,
'error' => $exception->getMessage()
]);
}
}
์ด Job์ ์ ๋ง ์ค์ํด! ๋ธ๋ก์ฒด์ธ ํธ๋์ญ์ ์ ์๋ช ์ฃผ๊ธฐ๋ฅผ ๊ด๋ฆฌํ๊ฑฐ๋ . 30์ด๋ง๋ค ์ํ๋ฅผ ์ฒดํฌํ๊ณ , 12๊ฐ ์ด์์ ์ปจํ์ ๋ฐ์ผ๋ฉด ์ต์ข ํ์ ์ฒ๋ฆฌ๋ฅผ ํด. ๋ง์ฝ ์คํจํ๋ฉด ๋กค๋ฐฑ๋ ์๋์ผ๋ก ์ฒ๋ฆฌํ์ง! ๐ฏ
๐ ๋ณด์ ๊ณ ๋ ค์ฌํญ
๋ธ๋ก์ฒด์ธ ์์คํ ์์ ๋ณด์์ ์ ๋ง์ ๋ง ์ค์ํด! ํ ๋ฒ ์๋ชป๋๋ฉด ๋์ดํฌ ์ ์๊ฑฐ๋ . ์ค์ ์๋น์ค๋ฅผ ์ด์ํ ๋ ๋ฐ๋์ ๊ณ ๋ คํด์ผ ํ ๋ณด์ ์์๋ค์ ์์๋ณด์. ๐ก๏ธ
โ ๏ธ ์ ๋ ํ์ง ๋ง์์ผ ํ ๊ฒ๋ค
1. Private Key๋ฅผ ์ฝ๋์ ํ๋์ฝ๋ฉ
์ ๋ ์ ๋ ์ ๋ผ! ํ๊ฒฝ๋ณ์๋ AWS KMS, HashiCorp Vault ๊ฐ์ ์ ๋ฌธ ํค ๊ด๋ฆฌ ์๋น์ค๋ฅผ ์ฌ์ฉํด์ผ ํด.
2. ํ๋ก ํธ์๋์์ ์ง์ ๋ธ๋ก์ฒด์ธ ํธ์ถ
์ฌ์ฉ์๊ฐ ์
์์ ์ผ๋ก ์กฐ์ํ ์ ์์ด. ๋ชจ๋ ๋ธ๋ก์ฒด์ธ ํธ์ถ์ ๋ฐ๋์ ๋ฐฑ์๋๋ฅผ ๊ฑฐ์ณ์ผ ํด.
3. ๊ฐ์ค๋น ์ ํ ์์ด ํธ๋์ญ์
์ ์ก
๊ฐ์ค๋น๊ฐ ํญ๋ฑํ ์ ์์ด. ํญ์ ์ํ์ ์ ์ค์ ํ๊ณ ๋ชจ๋ํฐ๋งํด์ผ ํด.
4. ์
๋ ฅ๊ฐ ๊ฒ์ฆ ์๋ต
SQL Injection์ฒ๋ผ ์ค๋งํธ ์ปจํธ๋ํธ๋ ๊ณต๊ฒฉ๋ฐ์ ์ ์์ด. ๋ชจ๋ ์
๋ ฅ๊ฐ์ ์ฒ ์ ํ ๊ฒ์ฆํด์ผ ํด.
์ด์ ์ค์ ๋ก ์ ์ฉํ ์ ์๋ ๋ณด์ ๊ฐํ ์ฝ๋๋ฅผ ์์ฑํด๋ณด์: ๐
๋ณด์ ๋ฏธ๋ค์จ์ด ์์ฑ
php artisan make:middleware ValidateBlockchainRequest
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
class ValidateBlockchainRequest
{
public function handle(Request $request, Closure $next)
{
$user = $request->user();
// Rate Limiting - ์ฌ์ฉ์๋น ๋ถ๋น 10ํ ์ ํ
$key = 'blockchain-request:' . $user->id;
if (RateLimiter::tooManyAttempts($key, 10)) {
$seconds = RateLimiter::availableIn($key);
return response()->json([
'success' => false,
'message' => 'Too many requests. Please try again in ' . $seconds . ' seconds.'
], 429);
}
RateLimiter::hit($key, 60);
// ๊ธ์ก ๊ฒ์ฆ
if ($request->has('amount')) {
$amount = $request->input('amount');
// ์ต์/์ต๋ ๊ธ์ก ์ฒดํฌ
if ($amount < 0.01 || $amount > 100000) {
return response()->json([
'success' => false,
'message' => 'Invalid amount. Must be between 0.01 and 100,000.'
], 400);
}
// ์์์ ์๋ฆฟ์ ์ฒดํฌ (์ต๋ 8์๋ฆฌ)
if (strlen(substr(strrchr($amount, "."), 1)) > 8) {
return response()->json([
'success' => false,
'message' => 'Amount can have maximum 8 decimal places.'
], 400);
}
}
// ์ง๊ฐ ์ฃผ์ ๊ฒ์ฆ
if ($request->has('wallet_address')) {
$address = $request->input('wallet_address');
if (!$this->isValidEthereumAddress($address)) {
return response()->json([
'success' => false,
'message' => 'Invalid Ethereum address.'
], 400);
}
}
// ์์ฌ์ค๋ฌ์ด ํจํด ๊ฐ์ง
if ($this->detectSuspiciousActivity($user)) {
// ๊ด๋ฆฌ์์๊ฒ ์๋ฆผ
\Log::warning('Suspicious blockchain activity detected', [
'user_id' => $user->id,
'ip' => $request->ip(),
'request' => $request->all()
]);
return response()->json([
'success' => false,
'message' => 'Your account has been temporarily restricted. Please contact support.'
], 403);
}
return $next($request);
}
protected function isValidEthereumAddress($address)
{
// 0x๋ก ์์ํ๋ 42์๋ฆฌ 16์ง์์ธ์ง ํ์ธ
return preg_match('/^0x[a-fA-F0-9]{40}$/', $address);
}
protected function detectSuspiciousActivity($user)
{
// ์ต๊ทผ 1์๊ฐ ๋์์ ๊ฑฐ๋ ํจํด ๋ถ์
$recentTransactions = \App\Models\PointTransaction::where('user_id', $user->id)
->where('created_at', '>=', now()->subHour())
->count();
// 1์๊ฐ์ 50ํ ์ด์์ด๋ฉด ์์ฌ
if ($recentTransactions > 50) {
return true;
}
// ์งง์ ์๊ฐ์ ๋๋ ํฌ์ธํธ ์ด๋
$recentAmount = \App\Models\PointTransaction::where('user_id', $user->id)
->where('created_at', '>=', now()->subMinutes(10))
->sum('amount');
if ($recentAmount > 10000) {
return true;
}
return false;
}
}
์ด ๋ฏธ๋ค์จ์ด๋ ์ฌ๋ฌ ์ธต์ ๋ณด์ ๊ฒ์ฆ์ ์ํํด:
| ๋ณด์ ๋ ์ด์ด | ๊ธฐ๋ฅ | ๋ชฉ์ |
|---|---|---|
| Rate Limiting | ๋ถ๋น ์์ฒญ ํ์ ์ ํ | DDoS ๊ณต๊ฒฉ ๋ฐฉ์ด |
| ๊ธ์ก ๊ฒ์ฆ | ์ต์/์ต๋๊ฐ, ์์์ ์ฒดํฌ | ์ค๋ฒํ๋ก์ฐ ๋ฐฉ์ง |
| ์ฃผ์ ๊ฒ์ฆ | ์ด๋๋ฆฌ์ ์ฃผ์ ํ์ ํ์ธ | ์๋ชป๋ ์ ์ก ๋ฐฉ์ง |
| ํจํด ๋ถ์ | ๋น์ ์ ๊ฑฐ๋ ํจํด ๊ฐ์ง | ์ด๋ทฐ์ง ์ฐจ๋จ |
๐ ๋์๋ณด๋์ ํต๊ณ
์์คํ ์ ์ด์ํ๋ค ๋ณด๋ฉด ์ ์ฒด์ ์ธ ํํฉ์ ํ๋์ ๋ณผ ์ ์๋ ๋์๋ณด๋๊ฐ ํ์ํด. ๊ด๋ฆฌ์์ฉ ๋์๋ณด๋๋ฅผ ๋ง๋ค์ด๋ณด์! ๐
Step 7: ํต๊ณ ์๋น์ค ์์ฑ
php artisan make:service StatisticsService
<?php
namespace App\Services;
use App\Models\PointTransaction;
use App\Models\UserWallet;
use App\Models\BlockchainLog;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
class StatisticsService
{
/**
* ์ ์ฒด ํต๊ณ ์กฐํ
*/
public function getOverallStats()
{
return Cache::remember('overall_stats', 300, function () {
return [
'total_users' => UserWallet::count(),
'total_supply' => PointTransaction::where('type', 'earn')
->where('status', 'confirmed')
->sum('amount'),
'total_burned' => PointTransaction::where('type', 'spend')
->where('status', 'confirmed')
->sum('amount'),
'total_transactions' => PointTransaction::count(),
'pending_transactions' => PointTransaction::where('status', 'pending')->count(),
'active_users_today' => PointTransaction::whereDate('created_at', today())
->distinct('user_id')
->count('user_id'),
'total_gas_spent' => BlockchainLog::sum('gas_used')
];
});
}
/**
* ์ผ๋ณ ๊ฑฐ๋๋ ํต๊ณ
*/
public function getDailyTransactionVolume($days = 30)
{
return PointTransaction::select(
DB::raw('DATE(created_at) as date'),
DB::raw('COUNT(*) as count'),
DB::raw('SUM(amount) as volume')
)
->where('created_at', '>=', now()->subDays($days))
->where('status', 'confirmed')
->groupBy('date')
->orderBy('date', 'asc')
->get();
}
/**
* ํฌ์ธํธ ๋ถํฌ ๋ถ์
*/
public function getPointDistribution()
{
return UserWallet::select(
DB::raw('CASE
WHEN balance < 100 THEN "0-100"
WHEN balance < 1000 THEN "100-1,000"
WHEN balance < 10000 THEN "1,000-10,000"
WHEN balance < 100000 THEN "10,000-100,000"
ELSE "100,000+"
END as range'),
DB::raw('COUNT(*) as count')
)
->groupBy('range')
->get();
}
/**
* ์์ ์ฌ์ฉ์ ๋ชฉ๋ก
*/
public function getTopUsers($limit = 10)
{
return UserWallet::with('user')
->orderBy('balance', 'desc')
->limit($limit)
->get();
}
/**
* ์ต๊ทผ ๊ฑฐ๋ ๋ด์ญ
*/
public function getRecentTransactions($limit = 20)
{
return PointTransaction::with('user')
->orderBy('created_at', 'desc')
->limit($limit)
->get();
}
/**
* ๊ฐ์ค๋น ๋ถ์
*/
public function getGasAnalysis()
{
return [
'average_gas' => BlockchainLog::avg('gas_used'),
'total_gas_cost' => BlockchainLog::sum(DB::raw('gas_used * gas_price')),
'highest_gas' => BlockchainLog::max('gas_used'),
'lowest_gas' => BlockchainLog::min('gas_used')
];
}
/**
* ์๊ฐ๋๋ณ ํ๋ ๋ถ์
*/
public function getHourlyActivity()
{
return PointTransaction::select(
DB::raw('HOUR(created_at) as hour'),
DB::raw('COUNT(*) as count')
)
->where('created_at', '>=', now()->subDays(7))
->groupBy('hour')
->orderBy('hour')
->get();
}
}
์ด ํต๊ณ ์๋น์ค๋ฅผ ํ์ฉํด์ ๊ด๋ฆฌ์ ๋์๋ณด๋ API๋ฅผ ๋ง๋ค ์ ์์ด. ์ค์๊ฐ์ผ๋ก ์์คํ ์ํ๋ฅผ ๋ชจ๋ํฐ๋งํ๊ณ , ์ด์ ์งํ๋ฅผ ๋น ๋ฅด๊ฒ ๊ฐ์งํ ์ ์์ง! ๐ฏ
๐จ ํ๋ก ํธ์๋ ์ฐ๋
๋ฐฑ์๋๊ฐ ์์ฑ๋์ผ๋ ์ด์ ์ฌ์ฉ์๊ฐ ์ค์ ๋ก ์ฌ์ฉํ ํ๋ก ํธ์๋๋ฅผ ๋ง๋ค์ด๋ณด์! Vue.js๋ฅผ ์ฌ์ฉํ ๊ฐ๋จํ ์์ ๋ฅผ ๋ณด์ฌ์ค๊ฒ. ๐ผ๏ธ
ํฌ์ธํธ ์์ก ์กฐํ ์ปดํฌ๋ํธ
<template>
<div class="reward-balance">
<div class="balance-card">
<div class="balance-header">
<h3>๐ฐ ๋ด ํฌ์ธํธ</h3>
<button @click="refreshBalance" :disabled="loading">
๐ ์๋ก๊ณ ์นจ
</button>
</div>
<div class="balance-amount">
<span class="amount">{{ formatNumber(balance) }}</span>
<span class="unit">RWP</span>
</div>
<div class="wallet-info">
<p>์ง๊ฐ ์ฃผ์: {{ shortenAddress(walletAddress) }}</p>
<p>๋ง์ง๋ง ๋๊ธฐํ: {{ lastSyncTime }}</p>
</div>
<div class="actions">
<button @click="showEarnModal" class="btn-primary">
โ ํฌ์ธํธ ์ ๋ฆฝ
</button>
<button @click="showSpendModal" class="btn-secondary">
๐ธ ํฌ์ธํธ ์ฌ์ฉ
</button>
</div>
</div>
<div class="recent-transactions">
<h4>์ต๊ทผ ๊ฑฐ๋ ๋ด์ญ</h4>
<div v-for="tx in transactions" :key="tx.id" class="transaction-item">
<div class="tx-info">
<span class="tx-type" :class="tx.type">
{{ tx.type === 'earn' ? 'โ' : 'โ' }}
</span>
<span class="tx-description">{{ tx.description }}</span>
</div>
<div class="tx-amount" :class="tx.type">
{{ tx.type === 'earn' ? '+' : '-' }}{{ tx.amount }}
</div>
<div class="tx-status" :class="tx.status">
{{ getStatusText(tx.status) }}
</div>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
export default {
name: 'RewardBalance',
data() {
return {
balance: 0,
walletAddress: '',
lastSyncTime: '',
transactions: [],
loading: false
};
},
mounted() {
this.loadBalance();
this.loadTransactions();
// 30์ด๋ง๋ค ์๋ ์๋ก๊ณ ์นจ
this.refreshInterval = setInterval(() => {
this.loadBalance();
}, 30000);
},
beforeUnmount() {
if (this.refreshInterval) {
clearInterval(this.refreshInterval);
}
},
methods: {
async loadBalance() {
try {
this.loading = true;
const response = await axios.get('/api/rewards/balance');
if (response.data.success) {
this.balance = response.data.balance;
this.walletAddress = response.data.wallet_address;
this.lastSyncTime = new Date().toLocaleString();
}
} catch (error) {
console.error('Failed to load balance:', error);
this.$toast.error('์์ก ์กฐํ์ ์คํจํ์ต๋๋ค.');
} finally {
this.loading = false;
}
},
async loadTransactions() {
try {
const response = await axios.get('/api/rewards/transactions');
if (response.data.success) {
this.transactions = response.data.transactions.data;
}
} catch (error) {
console.error('Failed to load transactions:', error);
}
},
async refreshBalance() {
await this.loadBalance();
this.$toast.success('์์ก์ด ์
๋ฐ์ดํธ๋์์ต๋๋ค!');
},
formatNumber(num) {
return new Intl.NumberFormat('ko-KR', {
minimumFractionDigits: 2,
maximumFractionDigits: 8
}).format(num);
},
shortenAddress(address) {
if (!address) return '';
return `${address.slice(0, 6)}...${address.slice(-4)}`;
},
getStatusText(status) {
const statusMap = {
'pending': 'โณ ๋๊ธฐ์ค',
'confirmed': 'โ
์๋ฃ',
'failed': 'โ ์คํจ'
};
return statusMap[status] || status;
},
showEarnModal() {
// ํฌ์ธํธ ์ ๋ฆฝ ๋ชจ๋ฌ ํ์
this.$emit('show-earn-modal');
},
showSpendModal() {
// ํฌ์ธํธ ์ฌ์ฉ ๋ชจ๋ฌ ํ์
this.$emit('show-spend-modal');
}
}
};
</script>
<style scoped>
.reward-balance {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.balance-card {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 16px;
padding: 30px;
color: white;
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
.balance-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.balance-header button {
background: rgba(255, 255, 255, 0.2);
border: none;
padding: 8px 16px;
border-radius: 8px;
color: white;
cursor: pointer;
transition: all 0.3s;
}
.balance-header button:hover {
background: rgba(255, 255, 255, 0.3);
}
.balance-amount {
font-size: 48px;
font-weight: bold;
margin: 20px 0;
}
.balance-amount .unit {
font-size: 24px;
opacity: 0.8;
margin-left: 10px;
}
.wallet-info {
opacity: 0.9;
font-size: 14px;
margin: 20px 0;
}
.actions {
display: flex;
gap: 10px;
margin-top: 20px;
}
.actions button {
flex: 1;
padding: 12px;
border: none;
border-radius: 8px;
font-weight: bold;
cursor: pointer;
transition: all 0.3s;
}
.btn-primary {
background: white;
color: #667eea;
}
.btn-secondary {
background: rgba(255, 255, 255, 0.2);
color: white;
}
.recent-transactions {
margin-top: 30px;
background: white;
border-radius: 12px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.transaction-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
border-bottom: 1px solid #f0f0f0;
}
.tx-info {
display: flex;
align-items: center;
gap: 10px;
}
.tx-type {
font-size: 20px;
}
.tx-amount.earn {
color: #10b981;
font-weight: bold;
}
.tx-amount.spend {
color: #ef4444;
font-weight: bold;
}
.tx-status.confirmed {
color: #10b981;
}
.tx-status.pending {
color: #f59e0b;
}
.tx-status.failed {
color: #ef4444;
}
</style>
์ด ์ปดํฌ๋ํธ๋ ์ฌ์ฉ์ ์นํ์ ์ธ UI๋ก ํฌ์ธํธ ์์ก๊ณผ ๊ฑฐ๋ ๋ด์ญ์ ๋ณด์ฌ์ค. ์ค์๊ฐ์ผ๋ก ์ ๋ฐ์ดํธ๋๊ณ , ํธ๋์ญ์ ์ํ๋ ์ง๊ด์ ์ผ๋ก ํ์ํ์ง! ๐
๐ ๋ฐฐํฌ์ ์ด์
๊ฐ๋ฐ์ด ์๋ฃ๋๋ค๋ฉด ์ด์ ์ค์ ์๋น์ค๋ก ๋ฐฐํฌํ ์ฐจ๋ก์ผ! ๋ฐฐํฌ ์ ์ ์ฒดํฌํด์ผ ํ ๊ฒ๋ค์ ์ ๋ฆฌํด๋ดค์ด. โ
๐ฏ ๋ฐฐํฌ ์ฒดํฌ๋ฆฌ์คํธ
1. ํ๊ฒฝ ์ค์
โ .env ํ์ผ์ ๋ชจ๋ ๋ฏผ๊ฐํ ์ ๋ณด ํ์ธ
โ APP_DEBUG=false ์ค์
โ ํ๋ก๋์
๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ํ
์คํธ
โ Redis/Queue ์ค์ ํ์ธ
2. ๋ธ๋ก์ฒด์ธ ์ค์
โ ๋ฉ์ธ๋ท RPC URL ์ค์
โ ์ค๋งํธ ์ปจํธ๋ํธ ๋ฉ์ธ๋ท ๋ฐฐํฌ
โ ๊ฐ์ค๋น ๋ชจ๋ํฐ๋ง ์ค์
โ ๋ฐฑ์
RPC ์๋ํฌ์ธํธ ์ค๋น
3. ๋ณด์
โ SSL ์ธ์ฆ์ ์ค์น
โ CORS ์ ์ฑ
์ค์
โ Rate Limiting ํ์ฑํ
โ ๋ฐฉํ๋ฒฝ ๊ท์น ์ค์
4. ๋ชจ๋ํฐ๋ง
โ ๋ก๊ทธ ์์ง ์์คํ
(ELK Stack)
โ ์๋ฌ ์ถ์ (Sentry)
โ ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง (New Relic)
โ ์๋ฆผ ์์คํ
์ค์
ํนํ ๋ธ๋ก์ฒด์ธ ์์คํ ์ ํ ๋ฒ ๋ฐฐํฌํ๋ฉด ์์ ์ด ์ด๋ ค์ฐ๋๊น ํ ์คํธ๋ท์์ ์ถฉ๋ถํ ํ ์คํธํ ํ์ ๋ฉ์ธ๋ท์ผ๋ก ์ด๋ํ๋ ๊ฒ ์ค์ํด! ๐ฏ
๐ก ์ค์ ํ๊ณผ ์ต์ ํ
์ค์ ๋ก ์๋น์ค๋ฅผ ์ด์ํ๋ฉด์ ๋ฐฐ์ด ๋ ธํ์ฐ๋ค์ ๊ณต์ ํ ๊ฒ! ์ด๋ฐ ํ๋ค์ ์๊ณ ์์ผ๋ฉด ํจ์ฌ ์์ ์ ์ธ ์๋น์ค๋ฅผ ๋ง๋ค ์ ์์ด. ๐
๐จ ์ฑ๋ฅ ์ต์ ํ ํ
1. ์บ์ฑ ์ ๋ต
๋ธ๋ก์ฒด์ธ ์กฐํ๋ ๋๋ฆฌ๋๊น ์์ฃผ ์กฐํํ๋ ๋ฐ์ดํฐ๋ Redis์ ์บ์ฑํด. ํนํ ์์ก ๊ฐ์ ๊ฑด 5๋ถ ์ ๋ ์บ์ํด๋ ๊ด์ฐฎ์.
2. ๋ฐฐ์น ์ฒ๋ฆฌ
์ฌ๋ฌ ์ฌ์ฉ์์๊ฒ ๋์์ ํฌ์ธํธ๋ฅผ ์ง๊ธํ ๋๋ ๊ฐ๋ณ ํธ๋์ญ์
๋ณด๋ค ๋ฐฐ์น ์ฒ๋ฆฌ๊ฐ ํจ์ฌ ํจ์จ์ ์ด์ผ. ๊ฐ์ค๋น๋ ์ ์ฝ๋๊ณ !
3. ๋ ์ด์ด2 ์๋ฃจ์
๊ณ ๋ ค
์ด๋๋ฆฌ์ ๋ฉ์ธ๋ท์ ๊ฐ์ค๋น๊ฐ ๋น์ธ๋๊น Polygon, Arbitrum ๊ฐ์ ๋ ์ด์ด2๋ฅผ ์ฌ์ฉํ๋ ๊ฒ๋ ์ข์ ์ ํ์ด์ผ.
4. ์คํ์ฒด์ธ ๊ณ์ฐ
๋ณต์กํ ๊ณ์ฐ์ ์ค๋งํธ ์ปจํธ๋ํธ๊ฐ ์๋๋ผ ๋ฐฑ์๋์์ ์ฒ๋ฆฌํ๊ณ , ๊ฒฐ๊ณผ๋ง ๋ธ๋ก์ฒด์ธ์ ๊ธฐ๋กํด.
๊ทธ๋ฆฌ๊ณ ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ๋ธ๋ก์ฒด์ธ ๊ฐ๋ฐ ์ ๋ฌธ๊ฐ๋ค์ ์กฐ์ธ์ ๊ตฌํ๋ ๊ฒ๋ ์ ๋ง ๋์์ด ๋ผ. ์ค์ ๊ฒฝํ์ด ์๋ ์ฌ๋๋ค์ ํผ๋๋ฐฑ์ ์ฑ ์์ ๋ฐฐ์ธ ์ ์๋ ๊ท์คํ ์ ๋ณด๋ค์ด๊ฑฐ๋ ! ๐
๐ ํธ๋ฌ๋ธ์ํ ๊ฐ์ด๋
๊ฐ๋ฐํ๋ค ๋ณด๋ฉด ๊ผญ ๋ง์ฃผ์น๋ ๋ฌธ์ ๋ค์ด ์์ด. ์์ฃผ ๋ฐ์ํ๋ ์ด์๋ค๊ณผ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ ๋ฆฌํด๋ดค์ด! ๐ง
| ๋ฌธ์ | ์์ธ | ํด๊ฒฐ ๋ฐฉ๋ฒ |
|---|---|---|
| ํธ๋์ญ์ ์ด pending์์ ๋ฉ์ถค | ๊ฐ์ค๋น ๋ถ์กฑ ๋๋ nonce ์ถฉ๋ | ๊ฐ์ค๋น๋ฅผ ๋์ด๊ฑฐ๋ nonce๋ฅผ ์๋์ผ๋ก ๊ด๋ฆฌ |
| ์์ก์ด ๋๊ธฐํ ์ ๋จ | ๋ธ๋ก ์ปจํ ๋๊ธฐ ์ค | 12๊ฐ ์ด์ ์ปจํ ํ ๋๊ธฐํํ๋๋ก ์ค์ |
| ๊ฐ์ค๋น๊ฐ ๋๋ฌด ๋์ | ๋คํธ์ํฌ ํผ์ก | ๊ฐ์ค๋น ์ํ์ ์ค์ , ํ๊ฐํ ์๊ฐ๋ ์ด์ฉ |
| ์ค๋งํธ ์ปจํธ๋ํธ ํธ์ถ ์คํจ | ๊ถํ ๋ถ์กฑ ๋๋ ์๋ชป๋ ํ๋ผ๋ฏธํฐ | ์ปจํธ๋ํธ ๊ถํ ํ์ธ, ํ๋ผ๋ฏธํฐ ํ์ ๊ฒ์ฆ |
๋๋ฒ๊น ํ
// ํธ๋์ญ์
์คํจ ์์ธ ํ์
$receipt = $web3->eth->getTransactionReceipt($txHash);
if ($receipt->status === '0x0') {
// ์คํจํ ํธ๋์ญ์
// Etherscan์์ ์์ธ ์๋ฌ ํ์ธ
$etherscanUrl = "https://etherscan.io/tx/{$txHash}";
// ๋๋ debug_traceTransaction์ผ๋ก ์์ธ ๋ก๊ทธ ํ์ธ
$trace = $web3->debug->traceTransaction($txHash);
}
// ๊ฐ์ค ์ถ์ ์คํจ ์
try {
$gas = $web3->eth->estimateGas($params);
} catch (Exception $e) {
// ์๋ฌ ๋ฉ์์ง์์ revert ์ด์ ํ์ฑ
$revertReason = $this->parseRevertReason($e->getMessage());
Log::error('Gas estimation failed', ['reason' => $revertReason]);
}
๐ ์ถ๊ฐ ํ์ต ์๋ฃ
์ฌ๊ธฐ๊น์ง ๋ฐ๋ผ์๋ค๋ฉด ์ ๋ง ๋๋จํด! ๐ ํ์ง๋ง ๋ธ๋ก์ฒด์ธ์ ๊ณ์ ๋ฐ์ ํ๋ ๋ถ์ผ๋ผ์ ๊พธ์คํ ๊ณต๋ถํด์ผ ํด. ์ถ์ฒํ๋ ํ์ต ์๋ฃ๋ค์ ์ ๋ฆฌํด๋ดค์ด:
๐ ์ถ์ฒ ๋ฆฌ์์ค
๊ณต์ ๋ฌธ์
- Laravel ๊ณต์ ๋ฌธ์: https://laravel.com/docs
- Web3.php ๋ฌธ์: https://web3php.readthedocs.io
- Solidity ๋ฌธ์: https://docs.soliditylang.org
- OpenZeppelin ์ปจํธ๋ํธ: https://docs.openzeppelin.com
์ปค๋ฎค๋ํฐ
- Ethereum Stack Exchange
- Laravel Korea ์ปค๋ฎค๋ํฐ
- Reddit r/ethdev
- Discord ๊ฐ๋ฐ์ ์ฑ๋๋ค
์ค์ต ํ๋ซํผ
- Remix IDE (์ค๋งํธ ์ปจํธ๋ํธ ๊ฐ๋ฐ)
- Hardhat (ํ
์คํธ ํ๋ ์์ํฌ)
- Tenderly (๋๋ฒ๊น
๋๊ตฌ)
- Alchemy University (๋ฌด๋ฃ ๊ฐ์)
๐ฏ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ ๋ง ๊ธด ์ฌ์ ์ด์์ง? ์ฐ๋ฆฌ๋ ๋ผ๋ผ๋ฒจ๊ณผ ๋ธ๋ก์ฒด์ธ์ ๊ฒฐํฉํด์ ์ค์ ๋ก ์๋ํ๋ ํฌ์ธํธ ๋ฆฌ์๋ ์์คํ ์ ๋ง๋ค์ด๋ดค์ด. ์ฒ์์๋ ๋ณต์กํด ๋ณด์์ง๋ง, ํ๋์ฉ ๋ฏ์ด๋ณด๋๊น ๊ทธ๋ ๊ฒ ์ด๋ ต์ง ์์์ง? ๐
ํต์ฌ์ ์ ๋ฆฌํ์๋ฉด:
โจ ํต์ฌ ์์ฝ
1. ํ์ด๋ธ๋ฆฌ๋ ์ํคํ
์ฒ
์ค์ํ ๊ฑฐ๋๋ ๋ธ๋ก์ฒด์ธ์, ๋ถ๊ฐ ์ ๋ณด๋ ์ผ๋ฐ DB์ ์ ์ฅํ๋ ๋ฐฉ์์ผ๋ก ํจ์จ์ฑ๊ณผ ๋ณด์์ ๋ชจ๋ ์ก์์ด.
2. ์ค๋งํธ ์ปจํธ๋ํธ
ERC-20 ๊ธฐ๋ฐ์ ํ ํฐ์ผ๋ก ํฌ์ธํธ๋ฅผ ๊ตฌํํ๊ณ , ์ผ์ผ ํ๋ ๊ฐ์ ๋ณด์ ์ฅ์น๋ฅผ ์ถ๊ฐํ์ด.
3. ๋ฐฑ์๋ ์๋น์ค
๋ผ๋ผ๋ฒจ์ ๊ฐ๋ ฅํ ๊ธฐ๋ฅ๋ค์ ํ์ฉํด์ ๋ธ๋ก์ฒด์ธ๊ณผ ํต์ ํ๊ณ , ํธ๋์ญ์
์ ๊ด๋ฆฌํ๋ ์์คํ
์ ๋ง๋ค์์ด.
4. ๋ณด์๊ณผ ๋ชจ๋ํฐ๋ง
Rate Limiting, ์
๋ ฅ๊ฐ ๊ฒ์ฆ, ํจํด ๋ถ์ ๋ฑ ๋ค์ธต ๋ณด์ ์์คํ
์ ๊ตฌ์ถํ์ด.
์ด์ ์ฌ๋ฌ๋ถ๋ ๋ธ๋ก์ฒด์ธ ๊ธฐ๋ฐ ์๋น์ค๋ฅผ ๋ง๋ค ์ ์์ด! ๋ฌผ๋ก ์ค์ ์๋น์ค๋ก ๋ง๋ค๋ ค๋ฉด ๋ ๋ง์ ๊ณ ๋ฏผ๊ณผ ํ ์คํธ๊ฐ ํ์ํ์ง๋ง, ์ด ๊ธ์ด ์ข์ ์ถ๋ฐ์ ์ด ๋์์ผ๋ฉด ์ข๊ฒ ์ด. ๐
ํน์ ๋งํ๋ ๋ถ๋ถ์ด ์๊ฑฐ๋ ๋ ๊น์ด ์๋ ๋ด์ฉ์ด ๊ถ๊ธํ๋ค๋ฉด, ์ฌ๋ฅ๋ท์์ ๋ธ๋ก์ฒด์ธ ์ ๋ฌธ๊ฐ๋ค์ ์ฐพ์๋ณด๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ. ์ค์ ๊ฒฝํ์ด ํ๋ถํ ๊ฐ๋ฐ์๋ค์ ๋ฉํ ๋ง์ ๋ฐ์ผ๋ฉด ํจ์ฌ ๋น ๋ฅด๊ฒ ์ฑ์ฅํ ์ ์๊ฑฐ๋ ! ๐ช
์, ์ด์ ์ฌ๋ฌ๋ถ์ ์ฐจ๋ก์ผ! ์ด ๊ฐ์ด๋๋ฅผ ๋ฐํ์ผ๋ก ๋ฉ์ง ๋ธ๋ก์ฒด์ธ ์๋น์ค๋ฅผ ๋ง๋ค์ด๋ณด์. ํ์ดํ ! ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.