-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.ts
92 lines (80 loc) · 2.12 KB
/
data.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { http, createConfig } from 'wagmi';
import mongoose from 'mongoose';
import { createAlchemyWeb3 } from '@alch/alchemy-web3';
import dotenv from 'dotenv';
dotenv.config();
// Infura URL'sini .env dosyasından al
const infuraUrl = process.env.API_INFURA_URL as string;
// Chain türünü elle tanımla
interface Chain {
id: number;
name: string;
network: string;
rpcUrls: {
default: {
http: string[];
};
};
nativeCurrency: {
name: string;
symbol: string;
decimals: number;
};
}
// Alternatif olarak mainnet ve sepolia tanımları
const mainnet: Chain = {
id: 1,
name: "Mainnet",
network: "mainnet",
rpcUrls: {
default: {
http: infuraUrl ? [infuraUrl] : [], // Eğer infuraUrl tanımlı değilse boş bir dizi kullanın
},
},
nativeCurrency: {
name: "Ether",
symbol: "ETH",
decimals: 18,
},
};
const sepolia: Chain = {
id: 11155111,
name: "Sepolia",
network: "sepolia",
rpcUrls: {
default: {
http: infuraUrl ? [infuraUrl.replace("mainnet", "sepolia")] : [], // Eğer infuraUrl tanımlı değilse boş bir dizi kullanın
},
},
nativeCurrency: {
name: "SepoliaETH",
symbol: "SEP",
decimals: 18,
},
};
// Wagmi Konfigürasyonu
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
});
// Alchemy ve MongoDB Ayarları
const alchemyApiKey = process.env.ALCHEMY_API_KEY as string;
const alchemyUrl = process.env.ALCHEMY_URL as string;
const alchemyWeb3 = createAlchemyWeb3(alchemyUrl);
const mongoUri = process.env.MONGO_URI as string;
mongoose.connect(mongoUri, {});
// MongoDB bağlantı durumu
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB bağlantı hatası:'));
db.once('open', function () {
console.log('MongoDB bağlantısı başarılı.');
});
// Veri izleme fonksiyonu
export async function observeData(userId: string, query: string) {
console.log(`Kullanıcı ${userId} tarafından yapılan sorgu: ${query}`);
// Mongoose ile izleme ve güvenlik işlemleri burada yapılır
}
export { alchemyWeb3, db };