@cordystackx/cordy_minikit 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cordystackx/cordy_minikit",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,2 +0,0 @@
1
- export default function AirDropFuacet(address: string, cost: number): Promise<boolean>;
2
- //# sourceMappingURL=AirDrop_Faucet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AirDrop_Faucet.d.ts","sourceRoot":"","sources":["../../controllers/AirDrop_Faucet.ts"],"names":[],"mappings":"AAUA,wBAA8B,aAAa,CACzC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,oBAsGb"}
@@ -1,93 +0,0 @@
1
- "use server";
2
- import { ethers, parseUnits } from 'ethers';
3
- import tokenAbi from '../config/ERC20_ABI.json';
4
- const tokenAddress = process.env.NEXT_PUBLIC_TOKENADDRESS || "";
5
- const rpcUrl = process.env.NEXT_PUBLIC_RPC_ENDPOINT || "";
6
- // Server-side environment variables (for backend/API routes)
7
- const privateKeyFromEnv = process.env.PRIVATE_KEY || "";
8
- export default async function AirDropFuacet(address, cost) {
9
- if (!address) {
10
- console.error("❌ Recipient address not found");
11
- return false;
12
- }
13
- const contractAddress = tokenAddress;
14
- if (!contractAddress) {
15
- console.error("❌ NEXT_PUBLIC_TOKENADDRESS not configured");
16
- return false;
17
- }
18
- try {
19
- let provider;
20
- let signer;
21
- const privateKey = privateKeyFromEnv;
22
- // Choose signing method
23
- if (privateKey) {
24
- // ⚠️ PRIVATE KEY SIGNING (Server-side or backend only)
25
- const endpoint = rpcUrl;
26
- if (!endpoint) {
27
- console.error("❌ NEXT_PUBLIC_RPC_ENDPOINT required for private key signing");
28
- return false;
29
- }
30
- console.log("🔐 Using private key signer (from environment)");
31
- provider = new ethers.JsonRpcProvider(endpoint);
32
- signer = new ethers.Wallet(privateKey, provider);
33
- }
34
- else {
35
- // 👛 WALLET SIGNING (User's wallet - MetaMask, etc.)
36
- console.log("👛 Using wallet signer");
37
- if (!window.ethereum) {
38
- console.error("❌ No wallet detected. Install MetaMask or similar.");
39
- return false;
40
- }
41
- provider = new ethers.BrowserProvider(window.ethereum);
42
- signer = await provider.getSigner();
43
- }
44
- // Get network info
45
- const network = await provider.getNetwork();
46
- console.log(`🌐 Network: ${network.name} (Chain ID: ${network.chainId})`);
47
- // Create contract instance
48
- const tokenContract = new ethers.Contract(contractAddress, tokenAbi, signer);
49
- // Get decimals from contract
50
- let decimals;
51
- try {
52
- decimals = await tokenContract.decimals();
53
- }
54
- catch {
55
- console.warn("⚠️ Could not fetch decimals, using default 18");
56
- decimals = 18;
57
- }
58
- const amount = parseUnits(String(cost), decimals);
59
- // Check balance
60
- const signerAddress = await signer.getAddress();
61
- const balance = await tokenContract.balanceOf(signerAddress);
62
- console.log(`💰 Balance: ${ethers.formatUnits(balance, decimals)} tokens`);
63
- console.log(`💸 Sending: ${ethers.formatUnits(amount, decimals)} tokens`);
64
- if (balance < amount) {
65
- console.error("❌ Insufficient balance");
66
- return false;
67
- }
68
- // Execute transfer
69
- console.log(`🚀 Initiating transfer to ${address}...`);
70
- const tx = await tokenContract.transfer(address, amount);
71
- console.log(`⏳ Transaction submitted: ${tx.hash}`);
72
- const receipt = await tx.wait();
73
- if (receipt && receipt.status === 1) {
74
- console.log(`✅ Transaction Complete! TX hash: ${receipt.hash}`);
75
- return true;
76
- }
77
- else {
78
- console.error("❌ Transaction Failed", receipt);
79
- return false;
80
- }
81
- }
82
- catch (err) {
83
- console.error("❌ Transaction error:", err);
84
- if (err.code === "INVALID_ARGUMENT") {
85
- console.error("💡 Check your private key format or wallet connection");
86
- }
87
- else if (err.code === "INSUFFICIENT_FUNDS") {
88
- console.error("💡 Not enough gas or token balance");
89
- }
90
- return false;
91
- }
92
- }
93
- ;