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 +1 -0
- package/dist/index.js +11 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
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: {
|
|
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
|
-
|
|
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
|
|
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);
|