@cordystackx/cordy_minikit 1.3.2 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../controllers/Transactions.tsx"],"names":[],"mappings":"AAKA,wBAA8B,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAmC1E"}
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,26 +1,39 @@
1
- import { ethers, parseUnits } from 'ethers';
2
- import tokenAbi from '../config/ERC20_ABI.json';
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 || "";
5
+ const rpcUrl = process.env.NEXT_PUBLIC_RPC_ENDPOINT || "https://mainnet.base.org";
4
6
  export default async function CordyStackTrans(address, cost) {
5
7
  if (!address) {
6
8
  console.error("Address Not Found");
7
9
  return false;
8
10
  }
9
11
  try {
10
- const provider = new ethers.BrowserProvider(window.ethereum);
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);
11
20
  const signer = await provider.getSigner();
12
21
  const tokenContract = new ethers.Contract(tokenAddress, tokenAbi, signer);
13
22
  const decimals = 18;
14
23
  const amount = parseUnits(String(cost), decimals);
15
- const balance = await tokenContract.balanceOf(await signer.getAddress());
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());
16
28
  if (balance < amount) {
17
- console.log("Insuficient Funds");
29
+ console.log("Insufficient Funds");
18
30
  return false;
19
31
  }
32
+ // ✅ Proceed with transfer
20
33
  const tx = await tokenContract.transfer(address, amount);
21
34
  const receipt = await tx.wait();
22
- if (receipt) {
23
- console.log("Transaction Complete TX hash", receipt);
35
+ if (receipt.status === 1) {
36
+ console.log("Transaction Complete! TX hash:", receipt.hash);
24
37
  return true;
25
38
  }
26
39
  else {
@@ -29,8 +42,7 @@ export default async function CordyStackTrans(address, cost) {
29
42
  }
30
43
  }
31
44
  catch (err) {
32
- console.error(err);
45
+ console.error("Transaction error:", err);
33
46
  return false;
34
47
  }
35
48
  }
36
- ;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cordystackx/cordy_minikit",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"