@rialo/ts-cdk 0.1.3 → 0.1.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.js CHANGED
@@ -451,8 +451,8 @@ var RialoError = class _RialoError extends Error {
451
451
 
452
452
  // src/constants.ts
453
453
  var DEFAULT_NUM_ACCOUNTS = 1;
454
- var URL_MAINNET = "https://mainnet.rialo.io:4100";
455
- var URL_TESTNET = "https://testnet.rialo.io:4100";
454
+ var URL_MAINNET = "https://mainnet.rialo.io:4101";
455
+ var URL_TESTNET = "https://testnet.rialo.io:4101";
456
456
  var URL_DEVNET = "https://devnet.rialo.io:4101";
457
457
  var URL_LOCALNET = "http://localhost:4100";
458
458
  var RIALO_MAINNET_CHAIN = {
@@ -6013,7 +6013,10 @@ var Message = class _Message {
6013
6013
  );
6014
6014
  }
6015
6015
  const validFromBytes = data.slice(cursor, cursor + 8);
6016
- const validFrom = BigInt.asUintN(64, new DataView(validFromBytes.buffer).getBigUint64(0));
6016
+ const validFrom = BigInt.asUintN(
6017
+ 64,
6018
+ new DataView(validFromBytes.buffer).getBigUint64(0, true)
6019
+ );
6017
6020
  cursor += 8;
6018
6021
  const [instructionsLength, newCursor2] = deserializeCompactU162(
6019
6022
  data,
@@ -6071,7 +6074,11 @@ var Message = class _Message {
6071
6074
  buf.push(...key.toBytes());
6072
6075
  });
6073
6076
  const validFromBuffer = new ArrayBuffer(8);
6074
- new DataView(validFromBuffer).setBigUint64(0, this.validFrom ?? BigInt(0));
6077
+ new DataView(validFromBuffer).setBigUint64(
6078
+ 0,
6079
+ this.validFrom ?? BigInt(0),
6080
+ true
6081
+ );
6075
6082
  buffer.push(...new Uint8Array(validFromBuffer));
6076
6083
  this.serializeCompactArray(buffer, this.instructions, (buf, ix) => {
6077
6084
  buf.push(ix.programIdIndex);
@@ -6603,6 +6610,7 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
6603
6610
  RpcErrorCode2["INTERNAL_ERROR"] = "INTERNAL_ERROR";
6604
6611
  RpcErrorCode2["TRANSACTION_REJECTED"] = "TRANSACTION_REJECTED";
6605
6612
  RpcErrorCode2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
6613
+ RpcErrorCode2["TRANSACTION_CONFIRMATION_TIMEOUT"] = "TRANSACTION_CONFIRMATION_TIMEOUT";
6606
6614
  RpcErrorCode2["ACCOUNT_NOT_FOUND"] = "ACCOUNT_NOT_FOUND";
6607
6615
  RpcErrorCode2["RATE_LIMIT_EXCEEDED"] = "RATE_LIMIT_EXCEEDED";
6608
6616
  RpcErrorCode2["NODE_UNHEALTHY"] = "NODE_UNHEALTHY";
@@ -6688,7 +6696,7 @@ var RpcError = class _RpcError extends Error {
6688
6696
  // src/rpc/clients/base-client.ts
6689
6697
  var BaseRpcClient = class {
6690
6698
  transport;
6691
- requestId = 1;
6699
+ requestId = 0;
6692
6700
  constructor(transport) {
6693
6701
  this.transport = transport;
6694
6702
  }
@@ -6698,7 +6706,7 @@ var BaseRpcClient = class {
6698
6706
  * Handles request serialization, response validation, and error mapping.
6699
6707
  */
6700
6708
  async call(method, params = []) {
6701
- const requestId = this.requestId++;
6709
+ const requestId = this.nextRequestId();
6702
6710
  const request = {
6703
6711
  jsonrpc: "2.0",
6704
6712
  id: requestId,
@@ -6739,6 +6747,14 @@ var BaseRpcClient = class {
6739
6747
  const response = data;
6740
6748
  return response.jsonrpc === "2.0" && typeof response.id === "number" && ("result" in response || "error" in response);
6741
6749
  }
6750
+ /**
6751
+ * Generates the next request ID with Overflow Protection.
6752
+ * @returns The next request ID.
6753
+ */
6754
+ nextRequestId() {
6755
+ this.requestId = (this.requestId + 1) % Number.MAX_SAFE_INTEGER;
6756
+ return this.requestId;
6757
+ }
6742
6758
  /**
6743
6759
  * Returns the configured RPC endpoint URL.
6744
6760
  */
@@ -6801,7 +6817,16 @@ function getLocalnetUrl() {
6801
6817
  // src/rpc/clients/query-client.ts
6802
6818
  var QueryRpcClient = class extends BaseRpcClient {
6803
6819
  /**
6804
- * Get the balance of an account
6820
+ * Retrieve the balance of an account in kelvins (smallest unit).
6821
+ *
6822
+ * @param pubkey - The public key of the account to query
6823
+ * @returns The account balance in kelvins
6824
+ *
6825
+ * @example
6826
+ * ```typescript
6827
+ * const balance = await client.getBalance(publicKey);
6828
+ * console.log(`Balance: ${balance} kelvins`);
6829
+ * ```
6805
6830
  */
6806
6831
  async getBalance(pubkey) {
6807
6832
  const result = await this.call("getBalance", [
@@ -6810,7 +6835,23 @@ var QueryRpcClient = class extends BaseRpcClient {
6810
6835
  return BigInt(result.value);
6811
6836
  }
6812
6837
  /**
6813
- * Get detailed information about an account
6838
+ * Retrieve detailed information about an account.
6839
+ *
6840
+ * Returns account data including balance, owner program, stored data,
6841
+ * executable status, and rent epoch.
6842
+ *
6843
+ * @param pubkey - The public key of the account to query
6844
+ * @returns Account information, or null if the account does not exist
6845
+ *
6846
+ * @example
6847
+ * ```typescript
6848
+ * const info = await client.getAccountInfo(publicKey);
6849
+ * if (info) {
6850
+ * console.log(`Owner: ${info.owner}`);
6851
+ * console.log(`Balance: ${info.balance} kelvins`);
6852
+ * console.log(`Data length: ${info.data.length} bytes`);
6853
+ * }
6854
+ * ```
6814
6855
  */
6815
6856
  async getAccountInfo(pubkey) {
6816
6857
  const result = await this.call("getAccountInfo", [{ address: pubkey.toString(), encoding: "base64" }]);
@@ -6826,14 +6867,42 @@ var QueryRpcClient = class extends BaseRpcClient {
6826
6867
  };
6827
6868
  }
6828
6869
  /**
6829
- * Get the current block height
6870
+ * Retrieve the current block height of the blockchain.
6871
+ *
6872
+ * The block height represents the number of blocks that have been
6873
+ * confirmed on the chain since genesis.
6874
+ *
6875
+ * @returns The current block height
6876
+ *
6877
+ * @example
6878
+ * ```typescript
6879
+ * const height = await client.getBlockHeight();
6880
+ * console.log(`Current block height: ${height}`);
6881
+ * ```
6830
6882
  */
6831
6883
  async getBlockHeight() {
6832
6884
  const result = await this.call("getBlockHeight", []);
6833
6885
  return BigInt(result);
6834
6886
  }
6835
6887
  /**
6836
- * Get detailed information about a transaction
6888
+ * Retrieve detailed information about a confirmed transaction.
6889
+ *
6890
+ * Returns transaction metadata including the block height it was
6891
+ * confirmed in and any execution errors.
6892
+ *
6893
+ * @param signature - The transaction signature to query
6894
+ * @returns Transaction information, or null if the transaction is not found
6895
+ *
6896
+ * @example
6897
+ * ```typescript
6898
+ * const tx = await client.getTransaction(signature);
6899
+ * if (tx) {
6900
+ * console.log(`Confirmed in block: ${tx.blockHeight}`);
6901
+ * if (tx.err) {
6902
+ * console.log(`Transaction failed: ${tx.err}`);
6903
+ * }
6904
+ * }
6905
+ * ```
6837
6906
  */
6838
6907
  async getTransaction(signature) {
6839
6908
  const result = await this.call("getTransaction", [signature]);
@@ -6842,20 +6911,45 @@ var QueryRpcClient = class extends BaseRpcClient {
6842
6911
  }
6843
6912
  return {
6844
6913
  signature,
6845
- slot: BigInt(result.slot),
6846
- blockTime: result.blockTime ? BigInt(result.blockTime) : void 0,
6847
- err: result.err
6914
+ blockHeight: BigInt(result.block_height ?? 0),
6915
+ err: result.err ?? result.meta?.err ?? void 0
6848
6916
  };
6849
6917
  }
6850
6918
  /**
6851
- * Get the total number of transactions processed since genesis
6919
+ * Retrieve the total number of transactions processed since genesis.
6920
+ *
6921
+ * @returns The total transaction count
6922
+ *
6923
+ * @example
6924
+ * ```typescript
6925
+ * const count = await client.getTransactionCount();
6926
+ * console.log(`Total transactions: ${count}`);
6927
+ * ```
6852
6928
  */
6853
6929
  async getTransactionCount() {
6854
6930
  const result = await this.call("getTransactionCount", []);
6855
6931
  return BigInt(result);
6856
6932
  }
6857
6933
  /**
6858
- * Get the status of multiple transaction signatures
6934
+ * Retrieve the status of multiple transaction signatures in a single request.
6935
+ *
6936
+ * Useful for batch-checking transaction confirmations. Returns null for
6937
+ * signatures that are not found or have expired from the status cache.
6938
+ *
6939
+ * @param signatures - Array of transaction signatures to query
6940
+ * @returns Array of signature statuses (null if signature not found)
6941
+ *
6942
+ * @example
6943
+ * ```typescript
6944
+ * const statuses = await client.getSignatureStatuses([sig1, sig2, sig3]);
6945
+ * statuses.forEach((status, i) => {
6946
+ * if (status) {
6947
+ * console.log(`${signatures[i]}: slot ${status.slot}, executed: ${status.executed}`);
6948
+ * } else {
6949
+ * console.log(`${signatures[i]}: not found`);
6950
+ * }
6951
+ * });
6952
+ * ```
6859
6953
  */
6860
6954
  async getSignatureStatuses(signatures) {
6861
6955
  const result = await this.call("getSignatureStatuses", [signatures]);
@@ -6865,13 +6959,26 @@ var QueryRpcClient = class extends BaseRpcClient {
6865
6959
  }
6866
6960
  return {
6867
6961
  slot: BigInt(status.slot),
6868
- confirmations: status.confirmations,
6962
+ executed: status.executed,
6869
6963
  err: status.err
6870
6964
  };
6871
6965
  });
6872
6966
  }
6873
6967
  /**
6874
- * Get epoch information
6968
+ * Retrieve information about the current epoch.
6969
+ *
6970
+ * Returns epoch metadata including the current epoch number, slot position
6971
+ * within the epoch, total slots per epoch, and current block height.
6972
+ *
6973
+ * @returns Current epoch information
6974
+ *
6975
+ * @example
6976
+ * ```typescript
6977
+ * const info = await client.getEpochInfo();
6978
+ * console.log(`Epoch: ${info.epoch}`);
6979
+ * console.log(`Slot ${info.slotIndex} of ${info.slotsInEpoch}`);
6980
+ * console.log(`Block height: ${info.blockHeight}`);
6981
+ * ```
6875
6982
  */
6876
6983
  async getEpochInfo() {
6877
6984
  const result = await this.call("getEpochInfo", []);
@@ -6885,7 +6992,22 @@ var QueryRpcClient = class extends BaseRpcClient {
6885
6992
  };
6886
6993
  }
6887
6994
  /**
6888
- * Get the health status of the node
6995
+ * Check the health status of the RPC node.
6996
+ *
6997
+ * Returns "ok" if the node is healthy. If the node is unhealthy,
6998
+ * returns an error message describing the issue.
6999
+ *
7000
+ * @returns "ok" if healthy, otherwise an error message
7001
+ *
7002
+ * @example
7003
+ * ```typescript
7004
+ * const health = await client.getHealth();
7005
+ * if (health === "ok") {
7006
+ * console.log("Node is healthy");
7007
+ * } else {
7008
+ * console.log(`Node unhealthy: ${health}`);
7009
+ * }
7010
+ * ```
6889
7011
  */
6890
7012
  async getHealth() {
6891
7013
  const result = await this.call("getHealth", []);
@@ -6894,9 +7016,32 @@ var QueryRpcClient = class extends BaseRpcClient {
6894
7016
  };
6895
7017
 
6896
7018
  // src/rpc/clients/transaction-client.ts
7019
+ var DEFAULT_MAX_RETRIES = 10;
7020
+ var DEFAULT_RETRY_DELAY_MS = 200;
6897
7021
  var TransactionRpcClient = class extends BaseRpcClient {
6898
7022
  /**
6899
- * Submit a signed transaction to the blockchain
7023
+ * Submit a signed transaction to the blockchain.
7024
+ *
7025
+ * Sends the transaction to the network for processing. The transaction
7026
+ * must be fully signed before submission. Returns immediately with the
7027
+ * transaction signature - use {@link confirmTransaction} or
7028
+ * {@link sendAndConfirmTransaction} to wait for confirmation.
7029
+ *
7030
+ * @param transaction - Serialized signed transaction bytes
7031
+ * @param options - Transaction submission options
7032
+ * @returns Transaction signature (base58 encoded)
7033
+ *
7034
+ * @example
7035
+ * ```typescript
7036
+ * const signature = await client.sendTransaction(signedTx);
7037
+ * console.log(`Submitted: ${signature}`);
7038
+ *
7039
+ * // With options
7040
+ * const signature = await client.sendTransaction(signedTx, {
7041
+ * skipPreflight: true,
7042
+ * maxRetries: 3,
7043
+ * });
7044
+ * ```
6900
7045
  */
6901
7046
  async sendTransaction(transaction, options) {
6902
7047
  const base64Tx = toBase64(transaction);
@@ -6912,15 +7057,162 @@ var TransactionRpcClient = class extends BaseRpcClient {
6912
7057
  return signature;
6913
7058
  }
6914
7059
  /**
6915
- * Request an airdrop of tokens to an account (devnet/testnet only)
7060
+ * Wait for a transaction to be confirmed.
7061
+ *
7062
+ * A transaction is considered confirmed when:
7063
+ * - It has been processed in a block (`blockHeight > 0`)
7064
+ *
7065
+ * @param signature - Transaction signature to monitor
7066
+ * @param options - Confirmation options
7067
+ * @returns Confirmed transaction details
7068
+ * @throws {TransactionFailedError} If the transaction fails on-chain
7069
+ * @throws {TransactionConfirmationTimeoutError} If confirmation times out
7070
+ */
7071
+ async confirmTransaction(signature, options) {
7072
+ const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;
7073
+ const retryDelay = options?.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
7074
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
7075
+ if (attempt > 0) {
7076
+ await this.sleep(retryDelay);
7077
+ }
7078
+ try {
7079
+ const txInfo = await this.getTransaction(signature);
7080
+ if (!txInfo) {
7081
+ continue;
7082
+ }
7083
+ if (txInfo.err) {
7084
+ return {
7085
+ signature,
7086
+ executed: false,
7087
+ err: txInfo.err
7088
+ };
7089
+ }
7090
+ if (txInfo.blockHeight && txInfo.blockHeight > 0n) {
7091
+ return {
7092
+ signature,
7093
+ executed: true,
7094
+ err: void 0
7095
+ };
7096
+ }
7097
+ } catch (error) {
7098
+ if (error instanceof RpcError && error.code === "TRANSACTION_REJECTED" /* TRANSACTION_REJECTED */) {
7099
+ throw error;
7100
+ }
7101
+ }
7102
+ }
7103
+ throw new RpcError(
7104
+ "TRANSACTION_CONFIRMATION_TIMEOUT" /* TRANSACTION_CONFIRMATION_TIMEOUT */,
7105
+ "Transaction confirmation timed out",
7106
+ {
7107
+ signature,
7108
+ maxRetries
7109
+ }
7110
+ );
7111
+ }
7112
+ /**
7113
+ * Submit a signed transaction and wait for confirmation.
7114
+ *
7115
+ * Polls the transaction status until it is confirmed (blockHeight > 0),
7116
+ * or until the maximum number of retries is reached.
7117
+ *
7118
+ * @param transaction - Serialized signed transaction bytes
7119
+ * @param options - Transaction submission and confirmation options
7120
+ * @returns Confirmed transaction details
7121
+ * @throws {TransactionFailedError} If the transaction fails on-chain
7122
+ * @throws {TransactionConfirmationTimeoutError} If confirmation times out
7123
+ *
7124
+ * @example
7125
+ * ```typescript
7126
+ * const result = await client.sendAndConfirmTransaction(signedTx);
7127
+ * console.log(`Confirmed in block ${result.blockHeight}, executed: ${result.executed}`);
7128
+ *
7129
+ * // With custom retry settings
7130
+ * const result = await client.sendAndConfirmTransaction(signedTx, {
7131
+ * maxRetries: 3,
7132
+ * retryDelay: 500,
7133
+ * });
7134
+ * ```
7135
+ */
7136
+ async sendAndConfirmTransaction(transaction, options) {
7137
+ const signature = await this.sendTransaction(transaction, options);
7138
+ return await this.confirmTransaction(signature, options);
7139
+ }
7140
+ /**
7141
+ * Request an airdrop of tokens to an account.
7142
+ *
7143
+ * **Note**: Only available on devnet and testnet networks.
7144
+ *
7145
+ * Returns immediately with the airdrop transaction signature.
7146
+ * Use {@link requestAirdropAndConfirm} to wait for the airdrop to complete.
7147
+ *
7148
+ * @param pubkey - The public key of the account to receive tokens
7149
+ * @param amount - Amount to airdrop in kelvins (smallest unit)
7150
+ * @returns Airdrop transaction signature
7151
+ *
7152
+ * @example
7153
+ * ```typescript
7154
+ * const signature = await client.requestAirdrop(publicKey, 1_000_000_000n);
7155
+ * console.log(`Airdrop requested: ${signature}`);
7156
+ * ```
6916
7157
  */
6917
7158
  async requestAirdrop(pubkey, amount) {
7159
+ if (amount > BigInt(Number.MAX_SAFE_INTEGER)) {
7160
+ throw new RpcError(
7161
+ "INVALID_PARAMS" /* INVALID_PARAMS */,
7162
+ `Airdrop amount ${amount} exceeds maximum safe value`
7163
+ );
7164
+ }
6918
7165
  const signature = await this.call("requestAirdrop", [
6919
7166
  pubkey.toString(),
6920
7167
  Number(amount)
6921
7168
  ]);
6922
7169
  return signature;
6923
7170
  }
7171
+ /**
7172
+ * Request an airdrop of tokens and wait for confirmation.
7173
+ *
7174
+ * **Note**: Only available on devnet and testnet networks.
7175
+ *
7176
+ * Combines {@link requestAirdrop} and {@link confirmTransaction} into
7177
+ * a single call for convenience.
7178
+ *
7179
+ * @param pubkey - The public key of the account to receive tokens
7180
+ * @param amount - Amount to airdrop in kelvins (smallest unit)
7181
+ * @param options - Confirmation options (max retries, retry delay)
7182
+ * @returns Confirmed transaction details
7183
+ * @throws {RpcError} If the airdrop transaction fails or confirmation times out
7184
+ *
7185
+ * @example
7186
+ * ```typescript
7187
+ * const result = await client.requestAirdropAndConfirm(publicKey, 1_000_000_000n);
7188
+ * if (result.executed) {
7189
+ * console.log("Airdrop confirmed!");
7190
+ * }
7191
+ * ```
7192
+ */
7193
+ async requestAirdropAndConfirm(pubkey, amount, options) {
7194
+ const signature = await this.requestAirdrop(pubkey, amount);
7195
+ return await this.confirmTransaction(signature, options);
7196
+ }
7197
+ async getTransaction(signature) {
7198
+ const result = await this.call("getTransaction", [signature]);
7199
+ if (!result) {
7200
+ return null;
7201
+ }
7202
+ return {
7203
+ signature,
7204
+ blockHeight: BigInt(result.block_height ?? 0),
7205
+ err: result.err ?? result.meta?.err ?? void 0
7206
+ };
7207
+ }
7208
+ /**
7209
+ * Sleeps for a given number of milliseconds.
7210
+ * @param ms - The number of milliseconds to sleep.
7211
+ * @returns A promise that resolves when the sleep is complete.
7212
+ */
7213
+ sleep(ms) {
7214
+ return new Promise((resolve) => setTimeout(resolve, ms));
7215
+ }
6924
7216
  };
6925
7217
 
6926
7218
  // src/rpc/clients/client.ts
@@ -6947,6 +7239,12 @@ var RialoClient = class {
6947
7239
  getChainIdentifier() {
6948
7240
  return this.chain.id;
6949
7241
  }
7242
+ /**
7243
+ * Returns the chain configuration.
7244
+ */
7245
+ getChainConfig() {
7246
+ return this.chain;
7247
+ }
6950
7248
  /**
6951
7249
  * Retrieves the balance of an account in kelvins (smallest unit).
6952
7250
  */
@@ -7023,6 +7321,49 @@ var RialoClient = class {
7023
7321
  async requestAirdrop(pubkey, amount) {
7024
7322
  return await this.transactionClient.requestAirdrop(pubkey, amount);
7025
7323
  }
7324
+ /**
7325
+ * Submits a signed transaction and waits for confirmation.
7326
+ *
7327
+ * @param transaction - Serialized signed transaction bytes
7328
+ * @param options - Transaction submission and confirmation options
7329
+ * @returns Confirmed transaction details
7330
+ * @throws {TransactionFailedError} If the transaction fails on-chain
7331
+ * @throws {TransactionConfirmationTimeoutError} If confirmation times out
7332
+ *
7333
+ * @example
7334
+ * ```typescript
7335
+ * const result = await client.sendAndConfirmTransaction(signedTx);
7336
+ * console.log(`Confirmed in slot ${result.slot}`);
7337
+ * ```
7338
+ */
7339
+ async sendAndConfirmTransaction(transaction, options) {
7340
+ return await this.transactionClient.sendAndConfirmTransaction(
7341
+ transaction,
7342
+ options
7343
+ );
7344
+ }
7345
+ /**
7346
+ * Waits for a transaction to be confirmed.
7347
+ *
7348
+ * @param signature - Transaction signature to monitor
7349
+ * @param options - Confirmation options
7350
+ * @returns Confirmed transaction details
7351
+ */
7352
+ async confirmTransaction(signature, options) {
7353
+ return await this.transactionClient.confirmTransaction(signature, options);
7354
+ }
7355
+ /**
7356
+ * Requests an airdrop and waits for confirmation.
7357
+ *
7358
+ * **Note**: Only available on devnet and testnet.
7359
+ */
7360
+ async requestAirdropAndConfirm(pubkey, amount, options) {
7361
+ return await this.transactionClient.requestAirdropAndConfirm(
7362
+ pubkey,
7363
+ amount,
7364
+ options
7365
+ );
7366
+ }
7026
7367
  };
7027
7368
 
7028
7369
  // src/rpc/http-transport.ts
@@ -7124,46 +7465,71 @@ var HttpTransport = class {
7124
7465
  }
7125
7466
  }
7126
7467
  /**
7127
- * Handle HTTP error responses
7468
+ * Handle HTTP error responses.
7469
+ *
7470
+ * Parses the response body to extract JSON-RPC error details when available,
7471
+ * regardless of HTTP status code. Falls back to HTTP status-based error handling.
7128
7472
  */
7129
7473
  async handleHttpError(response, requestDetails, attempt) {
7130
7474
  const status = response.status;
7475
+ const isRetryable = status >= 500 || status === 429;
7476
+ const baseDetails = {
7477
+ ...requestDetails,
7478
+ httpStatus: status,
7479
+ url: this.url,
7480
+ attempts: attempt + 1
7481
+ };
7482
+ const { message, rpcCode, errorData } = await this.parseErrorResponse(
7483
+ response,
7484
+ status
7485
+ );
7131
7486
  if (status === 429) {
7132
7487
  return RpcError.rateLimitExceeded({
7133
- ...requestDetails,
7134
- httpStatus: status,
7135
- url: this.url,
7136
- attempts: attempt + 1
7488
+ ...baseDetails,
7489
+ serverError: errorData
7490
+ });
7491
+ }
7492
+ if (rpcCode !== void 0) {
7493
+ return RpcError.fromRpcCode(rpcCode, message, {
7494
+ ...baseDetails,
7495
+ serverError: errorData
7137
7496
  });
7138
7497
  }
7139
7498
  if (status >= 500) {
7140
- return RpcError.networkError(`Server error: ${status}`, {
7141
- ...requestDetails,
7142
- httpStatus: status,
7143
- url: this.url,
7144
- attempts: attempt + 1
7499
+ return RpcError.networkError(message, {
7500
+ ...baseDetails,
7501
+ serverError: errorData
7145
7502
  });
7146
7503
  }
7504
+ return new RpcError("NETWORK_ERROR" /* NETWORK_ERROR */, message, baseDetails, isRetryable);
7505
+ }
7506
+ /**
7507
+ * Parse error response body to extract message and RPC error code.
7508
+ *
7509
+ * Handles multiple formats:
7510
+ * - JSON-RPC error: { error: { code, message, data? } }
7511
+ * - Simple JSON: { message: "..." }
7512
+ * - Non-JSON responses
7513
+ */
7514
+ async parseErrorResponse(response, status) {
7147
7515
  let message = `HTTP ${status}: ${response.statusText}`;
7516
+ let rpcCode;
7517
+ let errorData;
7148
7518
  try {
7149
- const errorData = await response.json();
7150
- if (errorData && typeof errorData === "object" && "message" in errorData) {
7151
- message = String(errorData.message);
7519
+ errorData = await response.json();
7520
+ if (errorData && typeof errorData === "object") {
7521
+ const data = errorData;
7522
+ if (data.error && typeof data.error === "object" && "message" in data.error) {
7523
+ const rpcError = data.error;
7524
+ message = String(rpcError.message);
7525
+ rpcCode = typeof rpcError.code === "number" ? rpcError.code : void 0;
7526
+ } else if ("message" in data) {
7527
+ message = String(data.message);
7528
+ }
7152
7529
  }
7153
7530
  } catch {
7154
7531
  }
7155
- return new RpcError(
7156
- "NETWORK_ERROR" /* NETWORK_ERROR */,
7157
- message,
7158
- {
7159
- ...requestDetails,
7160
- httpStatus: status,
7161
- url: this.url,
7162
- attempts: attempt + 1
7163
- },
7164
- false
7165
- // 4xx errors are not retryable
7166
- );
7532
+ return { message, rpcCode, errorData };
7167
7533
  }
7168
7534
  /**
7169
7535
  * Returns the configured RPC endpoint URL.
@@ -7175,10 +7541,9 @@ var HttpTransport = class {
7175
7541
 
7176
7542
  // src/rpc/index.ts
7177
7543
  function createRialoClient(config) {
7178
- const { chain: chain2, endpoint, transport } = config;
7179
- const url = endpoint ?? chain2.rpcUrl;
7180
- const httpTransport = new HttpTransport(url, transport);
7181
- return new RialoClient(httpTransport, config.chain);
7544
+ const { chain: chain2, transport } = config;
7545
+ const httpTransport = new HttpTransport(chain2.rpcUrl, transport);
7546
+ return new RialoClient(httpTransport, chain2);
7182
7547
  }
7183
7548
  function getDefaultRialoClientConfig(network) {
7184
7549
  switch (network) {