apinow-sdk 0.11.3 → 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 +15 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ class EthereumHandler {
|
|
|
75
75
|
}
|
|
76
76
|
const signedTx = await wallet.signTransaction(txRequest);
|
|
77
77
|
const txHash = await sendJsonRpc(rpc, 'eth_sendRawTransaction', [signedTx]);
|
|
78
|
-
console.
|
|
78
|
+
console.error(`Transaction sent: ${txHash}. Confirmation check not implemented.`);
|
|
79
79
|
return txHash;
|
|
80
80
|
}
|
|
81
81
|
catch (error) {
|
|
@@ -124,7 +124,7 @@ class ApiNow {
|
|
|
124
124
|
url.searchParams.append('txHash', txHash);
|
|
125
125
|
// Determine method reliably
|
|
126
126
|
const method = (opts.method || 'GET').toUpperCase();
|
|
127
|
-
console.
|
|
127
|
+
console.error(`txResponse: Preparing ${method} request to ${endpoint}`);
|
|
128
128
|
const fetchOptions = {
|
|
129
129
|
method: method,
|
|
130
130
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -133,7 +133,7 @@ class ApiNow {
|
|
|
133
133
|
if (method === 'GET' || method === 'HEAD') {
|
|
134
134
|
// --- GET/HEAD: Append data as query params ---
|
|
135
135
|
if (opts.data && typeof opts.data === 'object' && Object.keys(opts.data).length > 0) {
|
|
136
|
-
console.
|
|
136
|
+
console.error(`txResponse: Appending data as query params for GET request:`, opts.data);
|
|
137
137
|
// Convert potential non-string values in opts.data to strings for URLSearchParams
|
|
138
138
|
const paramsData = {};
|
|
139
139
|
for (const key in opts.data) {
|
|
@@ -152,12 +152,12 @@ class ApiNow {
|
|
|
152
152
|
else {
|
|
153
153
|
// --- POST/PUT/etc.: Set data as body ---
|
|
154
154
|
if (opts.data) {
|
|
155
|
-
console.
|
|
155
|
+
console.error(`txResponse: Setting data as body for ${method} request:`, opts.data);
|
|
156
156
|
fetchOptions.body = JSON.stringify(opts.data);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
try {
|
|
160
|
-
console.
|
|
160
|
+
console.error(`txResponse: Fetching ${url.toString()} with options:`, fetchOptions);
|
|
161
161
|
// Use the potentially modified URL and fetchOptions
|
|
162
162
|
return await fetchJson(url.toString(), fetchOptions);
|
|
163
163
|
}
|
|
@@ -168,33 +168,35 @@ class ApiNow {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
async infoBuyResponse(endpoint, userWalletPrivateKey, rpcUrl, opts = {}) {
|
|
171
|
-
console.
|
|
171
|
+
console.error(`Starting infoBuyResponse for endpoint: ${endpoint}`);
|
|
172
172
|
const info = await this.info(endpoint);
|
|
173
|
-
console.
|
|
174
|
-
const { requiredAmount, walletAddress, chain, tokenAddress } = info;
|
|
173
|
+
console.error("Received info:", 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
|
-
console.
|
|
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);
|
|
190
|
-
console.
|
|
192
|
+
console.error(`Transaction sent: ${txHash}`);
|
|
191
193
|
if (!opts.fastMode) {
|
|
192
194
|
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
193
195
|
}
|
|
194
196
|
else {
|
|
195
197
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
196
198
|
}
|
|
197
|
-
console.
|
|
199
|
+
console.error(`Fetching response for tx: ${txHash}`);
|
|
198
200
|
// Create specific options for txResponse
|
|
199
201
|
const txResponseOpts = {
|
|
200
202
|
method: info.httpMethod || 'POST', // Use the method from info, default to POST
|