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 +1 -0
- package/dist/index.js +5 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
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
|
-
|
|
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
|
|
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);
|