apinow-sdk 0.11.4 → 0.11.6

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
@@ -127,7 +127,12 @@ class ApiNow {
127
127
  console.error(`txResponse: Preparing ${method} request to ${endpoint}`);
128
128
  const fetchOptions = {
129
129
  method: method,
130
- headers: { 'Content-Type': 'application/json' },
130
+ headers: {
131
+ 'Content-Type': 'application/json',
132
+ 'Accept': '*/*',
133
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
134
+ 'X-Transaction-Hash': txHash
135
+ },
131
136
  // body is set conditionally below
132
137
  };
133
138
  if (method === 'GET' || method === 'HEAD') {
@@ -171,19 +176,21 @@ class ApiNow {
171
176
  console.error(`Starting infoBuyResponse for endpoint: ${endpoint}`);
172
177
  const info = await this.info(endpoint);
173
178
  console.error("Received info:", info);
174
- const { requiredAmount, walletAddress, chain, tokenAddress } = info;
179
+ const { requiredAmount, walletAddress, chain, tokenAddress, decimals } = info;
175
180
  if (!chain || !this.handlers[chain]) {
176
181
  throw new Error(`Unsupported chain specified by endpoint: ${chain}`);
177
182
  }
178
183
  let amountBigInt;
179
184
  try {
180
- amountBigInt = parseUnits(requiredAmount, 18);
185
+ // Use info.decimals if available, otherwise default to 18 (for ETH)
186
+ const parseDecimals = (tokenAddress && decimals !== undefined) ? decimals : 18;
187
+ amountBigInt = parseUnits(requiredAmount, parseDecimals);
181
188
  if (amountBigInt <= 0n) {
182
189
  throw new Error('Required amount must be positive.');
183
190
  }
184
191
  }
185
192
  catch (e) {
186
- throw new Error(`Invalid requiredAmount format or value: ${requiredAmount}. Could not parse as 18-decimal number.`);
193
+ throw new Error(`Invalid requiredAmount format or value: ${requiredAmount}. Could not parse with ${(tokenAddress && decimals !== undefined) ? decimals : 18} decimals.`);
187
194
  }
188
195
  console.error(`Attempting payment: Chain=${chain}, To=${walletAddress}, Amount=${amountBigInt.toString()}, Token=${tokenAddress || 'Native'}`);
189
196
  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.6",
4
4
  "description": "ApiNow SDK · The endpoint vending machine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",