apinow-sdk 0.11.4 → 0.11.5

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/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ interface InfoResponse {
8
8
  httpMethod: string;
9
9
  tokenAddress?: string;
10
10
  chain: 'eth' | 'base';
11
+ decimals?: number;
11
12
  }
12
13
  declare class ApiNow {
13
14
  private handlers;
package/dist/index.js CHANGED
@@ -171,19 +171,21 @@ class ApiNow {
171
171
  console.error(`Starting infoBuyResponse for endpoint: ${endpoint}`);
172
172
  const info = await this.info(endpoint);
173
173
  console.error("Received info:", info);
174
- const { requiredAmount, walletAddress, chain, tokenAddress } = info;
174
+ const { requiredAmount, walletAddress, chain, tokenAddress, decimals } = info;
175
175
  if (!chain || !this.handlers[chain]) {
176
176
  throw new Error(`Unsupported chain specified by endpoint: ${chain}`);
177
177
  }
178
178
  let amountBigInt;
179
179
  try {
180
- amountBigInt = parseUnits(requiredAmount, 18);
180
+ // Use info.decimals if available, otherwise default to 18 (for ETH)
181
+ const parseDecimals = (tokenAddress && decimals !== undefined) ? decimals : 18;
182
+ amountBigInt = parseUnits(requiredAmount, parseDecimals);
181
183
  if (amountBigInt <= 0n) {
182
184
  throw new Error('Required amount must be positive.');
183
185
  }
184
186
  }
185
187
  catch (e) {
186
- throw new Error(`Invalid requiredAmount format or value: ${requiredAmount}. Could not parse as 18-decimal number.`);
188
+ throw new Error(`Invalid requiredAmount format or value: ${requiredAmount}. Could not parse with ${(tokenAddress && decimals !== undefined) ? decimals : 18} decimals.`);
187
189
  }
188
190
  console.error(`Attempting payment: Chain=${chain}, To=${walletAddress}, Amount=${amountBigInt.toString()}, Token=${tokenAddress || 'Native'}`);
189
191
  const txHash = await this.buy(walletAddress, amountBigInt, userWalletPrivateKey, chain, rpcUrl, tokenAddress, opts.fastMode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apinow-sdk",
3
- "version": "0.11.4",
3
+ "version": "0.11.5",
4
4
  "description": "ApiNow SDK · The endpoint vending machine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",