@cordystackx/cordy_minikit 1.3.1 → 1.3.3
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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"AAOA,wBAA8B,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAgD1E"}
|
|
@@ -1,27 +1,39 @@
|
|
|
1
|
-
import { ethers, parseUnits } from
|
|
2
|
-
import tokenAbi from
|
|
1
|
+
import { ethers, parseUnits } from "ethers";
|
|
2
|
+
import tokenAbi from "../config/ERC20_ABI.json";
|
|
3
|
+
import { CoinbaseWalletSDK } from "@coinbase/wallet-sdk";
|
|
3
4
|
const tokenAddress = process.env.NEXT_PUBLIC_TOKENADDRESS || "";
|
|
4
|
-
const
|
|
5
|
+
const rpcUrl = process.env.NEXT_PUBLIC_RPC_ENDPOINT || "https://mainnet.base.org";
|
|
5
6
|
export default async function CordyStackTrans(address, cost) {
|
|
6
7
|
if (!address) {
|
|
7
8
|
console.error("Address Not Found");
|
|
8
9
|
return false;
|
|
9
10
|
}
|
|
10
11
|
try {
|
|
11
|
-
|
|
12
|
+
// ✅ Initialize Coinbase Wallet SDK
|
|
13
|
+
const coinbase = new CoinbaseWalletSDK({
|
|
14
|
+
appName: "Cordy Stack", // any name you want
|
|
15
|
+
appLogoUrl: "https://your-logo.png", // optional
|
|
16
|
+
});
|
|
17
|
+
// ✅ Connect to Coinbase Wallet
|
|
18
|
+
const ethereum = coinbase.makeWeb3Provider({ options: "all", keysUrl: rpcUrl }); // chainId handled by provider or wallet
|
|
19
|
+
const provider = new ethers.BrowserProvider(ethereum);
|
|
12
20
|
const signer = await provider.getSigner();
|
|
13
21
|
const tokenContract = new ethers.Contract(tokenAddress, tokenAbi, signer);
|
|
14
22
|
const decimals = 18;
|
|
15
23
|
const amount = parseUnits(String(cost), decimals);
|
|
16
|
-
|
|
24
|
+
// ✅ Always fetch balance using a read-only provider (not signer)
|
|
25
|
+
const readProvider = new ethers.JsonRpcProvider(rpcUrl);
|
|
26
|
+
const readContract = new ethers.Contract(tokenAddress, tokenAbi, readProvider);
|
|
27
|
+
const balance = await readContract.balanceOf(await signer.getAddress());
|
|
17
28
|
if (balance < amount) {
|
|
18
|
-
console.log("
|
|
29
|
+
console.log("Insufficient Funds");
|
|
19
30
|
return false;
|
|
20
31
|
}
|
|
21
|
-
|
|
32
|
+
// ✅ Proceed with transfer
|
|
33
|
+
const tx = await tokenContract.transfer(address, amount);
|
|
22
34
|
const receipt = await tx.wait();
|
|
23
|
-
if (receipt) {
|
|
24
|
-
console.log("Transaction Complete TX hash", receipt);
|
|
35
|
+
if (receipt.status === 1) {
|
|
36
|
+
console.log("Transaction Complete! TX hash:", receipt.hash);
|
|
25
37
|
return true;
|
|
26
38
|
}
|
|
27
39
|
else {
|
|
@@ -30,8 +42,7 @@ export default async function CordyStackTrans(address, cost) {
|
|
|
30
42
|
}
|
|
31
43
|
}
|
|
32
44
|
catch (err) {
|
|
33
|
-
console.error(err);
|
|
45
|
+
console.error("Transaction error:", err);
|
|
34
46
|
return false;
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
|
-
;
|