@rialo/ts-cdk 0.1.3 → 0.1.4

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