@cordystackx/cordy_minikit 0.9.6 → 0.9.7
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/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Built with **Wagmi**, **Viem**, **Ethers** and **TypeScript** (compiled to JS fo
|
|
|
21
21
|
- 🔗 **Wallet Connect / Disconnect**
|
|
22
22
|
Simple connect button and hooks for EVM-based wallets.
|
|
23
23
|
- 🧰 **Prebuilt UI Components**
|
|
24
|
-
Reusable components like `ConnectWalletBT`, `
|
|
24
|
+
Reusable components like `ConnectWalletBT`, `CordyStackTrans`.
|
|
25
25
|
- ⚙️ **Controllers**
|
|
26
26
|
Manage wallet actions, balances, and transactions.
|
|
27
27
|
- 🎨 **CSS Modules + CSS Variables**
|
|
@@ -136,7 +136,10 @@ export default function RootLayout({
|
|
|
136
136
|
|
|
137
137
|
## Usage
|
|
138
138
|
|
|
139
|
-
1.
|
|
139
|
+
1. Connect Buttons — ConnectWalletBT
|
|
140
|
+
The ConnectWalletBT component provides a plug-and-play wallet connection button for any Web3 application.
|
|
141
|
+
It automatically handles connecting, disconnecting, and managing wallet sessions using Wagmi and Viem under the hood.
|
|
142
|
+
|
|
140
143
|
```ts
|
|
141
144
|
import {
|
|
142
145
|
ConnectWalletBT
|
|
@@ -145,14 +148,24 @@ import {
|
|
|
145
148
|
<ConnectWalletBT />
|
|
146
149
|
```
|
|
147
150
|
|
|
148
|
-
2.
|
|
151
|
+
2. Button Transactions - CordyStackTrans
|
|
152
|
+
|
|
153
|
+
The CordyStackTrans function provides a simple and reusable transaction handler for EVM-based networks.
|
|
154
|
+
It allows developers to trigger ERC20 or native token transfers directly from UI components with minimal setup.
|
|
155
|
+
|
|
149
156
|
```ts
|
|
150
|
-
import {
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
import { CordyStackTrans } from "@cordystackx/cordy_minikit";
|
|
158
|
+
|
|
159
|
+
// Example Usage
|
|
160
|
+
CordyStackTrans(address: string, cost: number);
|
|
153
161
|
|
|
154
|
-
|
|
162
|
+
const trans = CordyStackTrans();
|
|
155
163
|
|
|
164
|
+
if (trans) {
|
|
165
|
+
return true; // Transaction successfull
|
|
166
|
+
} else {
|
|
167
|
+
return false; // Transaction failed or rejected
|
|
168
|
+
}
|
|
156
169
|
```
|
|
157
170
|
|
|
158
171
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export default function CordyStackTrans(address: string, cost: number): Promise<
|
|
1
|
+
export default function CordyStackTrans(address: string, cost: number): Promise<boolean>;
|
|
2
2
|
//# sourceMappingURL=Transactions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"AAMA,wBAA8B,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"AAMA,wBAA8B,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAmC1E"}
|
|
@@ -3,8 +3,10 @@ import tokenAbi from '../config/ERC20_ABI.json';
|
|
|
3
3
|
const tokenAddress = process.env.NEXT_PUBLIC_TOKENADDRESS || "";
|
|
4
4
|
const platformAddress = process.env.NEXT_PUBLIC_PLATFORM_ADDRESS || "";
|
|
5
5
|
export default async function CordyStackTrans(address, cost) {
|
|
6
|
-
if (!address)
|
|
7
|
-
|
|
6
|
+
if (!address) {
|
|
7
|
+
console.error("Address Not Found");
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
8
10
|
try {
|
|
9
11
|
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
10
12
|
const signer = await provider.getSigner();
|
|
@@ -13,19 +15,23 @@ export default async function CordyStackTrans(address, cost) {
|
|
|
13
15
|
const amount = parseUnits(String(cost), decimals);
|
|
14
16
|
const balance = await tokenContract.balanceOf(await signer.getAddress());
|
|
15
17
|
if (balance < amount) {
|
|
16
|
-
|
|
18
|
+
console.log("Insuficient Funds");
|
|
19
|
+
return false;
|
|
17
20
|
}
|
|
18
21
|
const tx = await tokenContract.transfer(platformAddress, amount);
|
|
19
22
|
const receipt = await tx.wait();
|
|
20
23
|
if (receipt) {
|
|
21
|
-
|
|
24
|
+
console.log("Transaction Complete TX hash", receipt);
|
|
25
|
+
return true;
|
|
22
26
|
}
|
|
23
27
|
else {
|
|
24
|
-
|
|
28
|
+
console.log("Transaction Failed", receipt);
|
|
29
|
+
return false;
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
catch (err) {
|
|
28
33
|
console.error(err);
|
|
34
|
+
return false;
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
;
|