Webhook 설정 튜토리얼
1. Webhook이란?
Webhook을 설정하면 MetaCivia의 이벤트를 실시간으로 수신할 수 있습니다.
2. Webhook 등록
await fetch('https://metacivia-backend.pages.dev/api/external/webhook', {
method: 'POST',
headers: {
'X-API-Key': 'your-api-key-here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://your-webhook-url.com/events',
events: ['citizen_minted', 'ritual_completed', 'rank_up']
})
})지원 이벤트
citizen_minted: 시민 민팅ritual_completed: Ritual 완료rank_up: Rank 승급era_completed: Era 완료*: 모든 이벤트
3. Webhook 수신 서버 구현
Node.js 예제
const express = require('express')
const app = express()
app.use(express.json())
app.post('/events', (req, res) => {
const { type, data, timestamp } = req.body
console.log('Event received:', type)
console.log('Data:', data)
console.log('Timestamp:', timestamp)
// 이벤트 처리 로직
switch (type) {
case 'citizen_minted':
// 시민 민팅 처리
break
case 'ritual_completed':
// Ritual 완료 처리
break
case 'rank_up':
// Rank 승급 처리
break
}
res.status(200).send('OK')
})
app.listen(3000, () => {
console.log('Webhook server listening on port 3000')
})4. 이벤트 형식
{
"type": "citizen_minted",
"data": {
"walletAddress": "0x1234...",
"status": "observer"
},
"timestamp": 1234567890
}5. 보안
- Webhook URL은 HTTPS여야 합니다
- API Key를 안전하게 보관하세요
- 이벤트 검증 로직을 구현하세요