@rialo/ts-cdk 0.1.2 → 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/README.md +27 -2
- package/dist/index.d.mts +938 -661
- package/dist/index.d.ts +938 -661
- package/dist/index.js +1793 -1505
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1789 -1504
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -135,6 +135,89 @@ declare class RialoError extends Error {
|
|
|
135
135
|
static serialization(message: string): RialoError;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
interface HttpTransportConfig {
|
|
139
|
+
/** Request timeout in milliseconds */
|
|
140
|
+
timeout?: number;
|
|
141
|
+
/** Maximum number of retry attempts */
|
|
142
|
+
maxRetries?: number;
|
|
143
|
+
/** Base delay for exponential backoff (ms) */
|
|
144
|
+
retryBaseDelay?: number;
|
|
145
|
+
/** Maximum retry delay (ms) */
|
|
146
|
+
retryMaxDelay?: number;
|
|
147
|
+
/** Custom headers to include in requests */
|
|
148
|
+
headers?: Record<string, string>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* HTTP transport with built-in retry logic and timeout handling.
|
|
152
|
+
*
|
|
153
|
+
* Features:
|
|
154
|
+
* - Automatic retries with exponential backoff
|
|
155
|
+
* - Request timeouts using AbortController
|
|
156
|
+
* - Network error recovery
|
|
157
|
+
* - Rate limit handling
|
|
158
|
+
* - Proper HTTP status code handling
|
|
159
|
+
*/
|
|
160
|
+
declare class HttpTransport {
|
|
161
|
+
private readonly url;
|
|
162
|
+
private readonly config;
|
|
163
|
+
constructor(url: string, config?: HttpTransportConfig);
|
|
164
|
+
/**
|
|
165
|
+
* Makes an HTTP request with automatic retry logic.
|
|
166
|
+
*
|
|
167
|
+
* Retries are attempted for network errors and server errors (5xx).
|
|
168
|
+
* Uses exponential backoff between retry attempts.
|
|
169
|
+
*/
|
|
170
|
+
request(body: string, requestDetails?: Record<string, unknown>): Promise<unknown>;
|
|
171
|
+
/**
|
|
172
|
+
* Make a single HTTP request with timeout
|
|
173
|
+
*/
|
|
174
|
+
private makeRequest;
|
|
175
|
+
/**
|
|
176
|
+
* Handle HTTP error responses.
|
|
177
|
+
*
|
|
178
|
+
* Parses the response body to extract JSON-RPC error details when available,
|
|
179
|
+
* regardless of HTTP status code. Falls back to HTTP status-based error handling.
|
|
180
|
+
*/
|
|
181
|
+
private handleHttpError;
|
|
182
|
+
/**
|
|
183
|
+
* Parse error response body to extract message and RPC error code.
|
|
184
|
+
*
|
|
185
|
+
* Handles multiple formats:
|
|
186
|
+
* - JSON-RPC error: { error: { code, message, data? } }
|
|
187
|
+
* - Simple JSON: { message: "..." }
|
|
188
|
+
* - Non-JSON responses
|
|
189
|
+
*/
|
|
190
|
+
private parseErrorResponse;
|
|
191
|
+
/**
|
|
192
|
+
* Returns the configured RPC endpoint URL.
|
|
193
|
+
*/
|
|
194
|
+
getUrl(): string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
type IdentifierString = `${string}:${string}`;
|
|
198
|
+
type RialoNetwork = "mainnet" | "devnet" | "testnet" | "localnet";
|
|
199
|
+
interface ChainDefinition {
|
|
200
|
+
/** * The Wallet Standard Chain Identifier.
|
|
201
|
+
* e.g., 'rialo:mainnet', 'rialo:devnet'
|
|
202
|
+
*/
|
|
203
|
+
id: IdentifierString;
|
|
204
|
+
/** Human-readable name for UI */
|
|
205
|
+
name: string;
|
|
206
|
+
/** The default RPC URL for this chain */
|
|
207
|
+
rpcUrl: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Configuration for the Rialo Client.
|
|
211
|
+
*/
|
|
212
|
+
interface RialoClientConfig {
|
|
213
|
+
/**
|
|
214
|
+
* The Chain Definition.
|
|
215
|
+
* Can be a preset (RIALO_MAINNET) or a custom object.
|
|
216
|
+
*/
|
|
217
|
+
chain: ChainDefinition;
|
|
218
|
+
transport?: HttpTransportConfig;
|
|
219
|
+
}
|
|
220
|
+
|
|
138
221
|
/** Default number of accounts to derive in HD wallets */
|
|
139
222
|
declare const DEFAULT_NUM_ACCOUNTS: number;
|
|
140
223
|
/** Rialo mainnet RPC URL */
|
|
@@ -145,6 +228,10 @@ declare const URL_TESTNET: string;
|
|
|
145
228
|
declare const URL_DEVNET: string;
|
|
146
229
|
/** Rialo localnet RPC URL */
|
|
147
230
|
declare const URL_LOCALNET: string;
|
|
231
|
+
declare const RIALO_MAINNET_CHAIN: ChainDefinition;
|
|
232
|
+
declare const RIALO_TESTNET_CHAIN: ChainDefinition;
|
|
233
|
+
declare const RIALO_DEVNET_CHAIN: ChainDefinition;
|
|
234
|
+
declare const RIALO_LOCALNET_CHAIN: ChainDefinition;
|
|
148
235
|
/** System program ID */
|
|
149
236
|
declare const SYSTEM_PROGRAM_ID: string;
|
|
150
237
|
/** Base derivation path for Rialo wallets (BIP44 coin type 756) */
|
|
@@ -154,56 +241,6 @@ declare const KELVIN_PER_RLO: number;
|
|
|
154
241
|
declare const PUBLIC_KEY_LENGTH: number;
|
|
155
242
|
declare const SECRET_KEY_LENGTH: number;
|
|
156
243
|
declare const SIGNATURE_LENGTH: number;
|
|
157
|
-
declare const BLOCKHASH_LENGTH: number;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Represents a 32-byte blockhash used for transaction replay protection.
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* ```typescript
|
|
164
|
-
* // From RPC response
|
|
165
|
-
* const blockhash = Blockhash.fromString(rpcBlockhash);
|
|
166
|
-
*
|
|
167
|
-
* // Comparison
|
|
168
|
-
* if (blockhash1.equals(blockhash2)) {
|
|
169
|
-
* console.log("Same blockhash");
|
|
170
|
-
* }
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
declare class Blockhash {
|
|
174
|
-
private readonly bytes;
|
|
175
|
-
private constructor();
|
|
176
|
-
/**
|
|
177
|
-
* Creates a Blockhash from raw bytes.
|
|
178
|
-
*
|
|
179
|
-
* @param bytes - 32-byte blockhash
|
|
180
|
-
* @throws {CryptoError} If bytes length is not 32
|
|
181
|
-
*/
|
|
182
|
-
static fromBytes(bytes: Uint8Array): Blockhash;
|
|
183
|
-
/**
|
|
184
|
-
* Creates a Blockhash from a base58-encoded string.
|
|
185
|
-
*
|
|
186
|
-
* @param str - Base58-encoded blockhash
|
|
187
|
-
* @throws {CryptoError} If string is invalid or decodes to wrong length
|
|
188
|
-
*/
|
|
189
|
-
static fromString(str: string): Blockhash;
|
|
190
|
-
/**
|
|
191
|
-
* Returns a copy of the raw bytes.
|
|
192
|
-
*/
|
|
193
|
-
toBytes(): Uint8Array;
|
|
194
|
-
/**
|
|
195
|
-
* Returns the base58-encoded string representation.
|
|
196
|
-
*/
|
|
197
|
-
toString(): string;
|
|
198
|
-
/**
|
|
199
|
-
* Checks equality with another blockhash using constant-time comparison.
|
|
200
|
-
*/
|
|
201
|
-
equals(other: Blockhash): boolean;
|
|
202
|
-
/**
|
|
203
|
-
* JSON serialization (returns base58 string).
|
|
204
|
-
*/
|
|
205
|
-
toJSON(): string;
|
|
206
|
-
}
|
|
207
244
|
|
|
208
245
|
/**
|
|
209
246
|
* Error codes for cryptographic operations.
|
|
@@ -793,7 +830,6 @@ declare enum SystemInstruction {
|
|
|
793
830
|
*
|
|
794
831
|
* const tx = TransactionBuilder.create()
|
|
795
832
|
* .setPayer(fromPubkey)
|
|
796
|
-
* .setRecentBlockhash(blockhash)
|
|
797
833
|
* .addInstruction(instruction)
|
|
798
834
|
* .build();
|
|
799
835
|
* ```
|
|
@@ -810,87 +846,440 @@ declare function transferInstruction(from: PublicKey, to: PublicKey, amount: big
|
|
|
810
846
|
*/
|
|
811
847
|
declare function createAccount(from: PublicKey, newAccount: PublicKey, lamports: bigint, space: bigint, owner: PublicKey): Instruction;
|
|
812
848
|
|
|
813
|
-
interface HttpTransportConfig {
|
|
814
|
-
/** Request timeout in milliseconds */
|
|
815
|
-
timeout?: number;
|
|
816
|
-
/** Maximum number of retry attempts */
|
|
817
|
-
maxRetries?: number;
|
|
818
|
-
/** Base delay for exponential backoff (ms) */
|
|
819
|
-
retryBaseDelay?: number;
|
|
820
|
-
/** Maximum retry delay (ms) */
|
|
821
|
-
retryMaxDelay?: number;
|
|
822
|
-
/** Custom headers to include in requests */
|
|
823
|
-
headers?: Record<string, string>;
|
|
824
|
-
}
|
|
825
849
|
/**
|
|
826
|
-
*
|
|
850
|
+
* An unsigned transaction message ready to be signed.
|
|
827
851
|
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
*
|
|
852
|
+
* This is the data that gets signed by transaction signers.
|
|
853
|
+
* It's immutable to prevent accidental modification after creation.
|
|
854
|
+
*
|
|
855
|
+
* @example
|
|
856
|
+
* ```typescript
|
|
857
|
+
* const message = MessageBuilder.create()
|
|
858
|
+
* .setPayer(payer)
|
|
859
|
+
* .setValidFrom(validFrom)
|
|
860
|
+
* .addInstruction(transferInstruction)
|
|
861
|
+
* .build();
|
|
862
|
+
*
|
|
863
|
+
* // Serialize for signing
|
|
864
|
+
* const messageBytes = message.serialize();
|
|
865
|
+
* ```
|
|
834
866
|
*/
|
|
835
|
-
declare class
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
867
|
+
declare class Message {
|
|
868
|
+
/** Message header with signature requirements */
|
|
869
|
+
readonly header: MessageHeader;
|
|
870
|
+
/** All account public keys referenced in the transaction */
|
|
871
|
+
readonly accountKeys: readonly PublicKey[];
|
|
872
|
+
/** Transaction valid from (milliseconds since Unix epoch) */
|
|
873
|
+
validFrom?: bigint;
|
|
874
|
+
/** Compiled instructions with account indices */
|
|
875
|
+
readonly instructions: readonly CompiledInstruction[];
|
|
876
|
+
/** Cached serialized bytes */
|
|
877
|
+
private serializedCache?;
|
|
878
|
+
constructor(header: MessageHeader, accountKeys: readonly PublicKey[], validFrom: bigint, instructions: readonly CompiledInstruction[]);
|
|
839
879
|
/**
|
|
840
|
-
*
|
|
880
|
+
* Serialize message to bytes for signing.
|
|
881
|
+
* Result is cached for performance.
|
|
882
|
+
*/
|
|
883
|
+
serialize(): Uint8Array;
|
|
884
|
+
/**
|
|
885
|
+
* Deserialize a message from wire format.
|
|
841
886
|
*
|
|
842
|
-
*
|
|
843
|
-
*
|
|
887
|
+
* @param data - Serialized message bytes
|
|
888
|
+
* @returns Deserialized Message
|
|
844
889
|
*/
|
|
845
|
-
|
|
890
|
+
static deserialize(data: Uint8Array): Message;
|
|
891
|
+
private serializeInternal;
|
|
892
|
+
private serializeCompactArray;
|
|
893
|
+
private serializeCompactU16;
|
|
846
894
|
/**
|
|
847
|
-
*
|
|
895
|
+
* Get all signers required for this message.
|
|
848
896
|
*/
|
|
849
|
-
|
|
897
|
+
getSigners(): readonly PublicKey[];
|
|
850
898
|
/**
|
|
851
|
-
*
|
|
899
|
+
* Check if a public key is a required signer.
|
|
852
900
|
*/
|
|
853
|
-
|
|
901
|
+
isSignerRequired(pubkey: PublicKey): boolean;
|
|
854
902
|
/**
|
|
855
|
-
*
|
|
903
|
+
* Get the index of a signer in the signers array.
|
|
904
|
+
* Returns -1 if not a signer.
|
|
856
905
|
*/
|
|
857
|
-
|
|
906
|
+
getSignerIndex(pubkey: PublicKey): number;
|
|
858
907
|
}
|
|
859
908
|
|
|
860
909
|
/**
|
|
861
|
-
*
|
|
910
|
+
* Interface for signing messages and transactions.
|
|
862
911
|
*
|
|
863
|
-
*
|
|
912
|
+
* Enables multiple signing strategies:
|
|
913
|
+
* - **KeypairSigner**: Local keypair signing
|
|
914
|
+
* - **Browser Wallet**: Browser extension integration
|
|
915
|
+
* - **Hardware Wallet**: Ledger, Trezor, etc.
|
|
916
|
+
* - **Remote Signer**: API-based signing services
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* ```typescript
|
|
920
|
+
* // Browser wallet implementation
|
|
921
|
+
* class BrowserWalletSigner implements Signer {
|
|
922
|
+
* async getPublicKey(): Promise<PublicKey> {
|
|
923
|
+
* const pubkey = await window.rialoWallet.getPublicKey();
|
|
924
|
+
* return PublicKey.fromString(pubkey);
|
|
925
|
+
* }
|
|
926
|
+
*
|
|
927
|
+
* async signMessage(message: Uint8Array): Promise<Signature> {
|
|
928
|
+
* const sig = await window.rialoWallet.signMessage(message);
|
|
929
|
+
* return Signature.fromBytes(sig);
|
|
930
|
+
* }
|
|
931
|
+
* }
|
|
932
|
+
*
|
|
933
|
+
* // Usage
|
|
934
|
+
* const signer = new BrowserWalletSigner();
|
|
935
|
+
* const publicKey = await signer.getPublicKey();
|
|
936
|
+
* const signature = await signer.signMessage(message);
|
|
937
|
+
* ```
|
|
864
938
|
*/
|
|
865
|
-
|
|
866
|
-
protected readonly transport: HttpTransport;
|
|
867
|
-
private requestId;
|
|
868
|
-
constructor(transport: HttpTransport);
|
|
939
|
+
interface Signer {
|
|
869
940
|
/**
|
|
870
|
-
*
|
|
941
|
+
* Retrieves the signer's public key.
|
|
871
942
|
*
|
|
872
|
-
*
|
|
873
|
-
*/
|
|
874
|
-
protected call<T>(method: string, params?: unknown[]): Promise<T>;
|
|
875
|
-
/**
|
|
876
|
-
* Validate JSON-RPC response structure
|
|
943
|
+
* **Note**: May trigger wallet connection prompts for browser wallets.
|
|
877
944
|
*/
|
|
878
|
-
|
|
945
|
+
getPublicKey(): Promise<PublicKey>;
|
|
879
946
|
/**
|
|
880
|
-
*
|
|
947
|
+
* Signs arbitrary message bytes.
|
|
948
|
+
*
|
|
949
|
+
* @param message - Message bytes to sign
|
|
950
|
+
* @returns Ed25519 signature over the message
|
|
881
951
|
*/
|
|
882
|
-
|
|
952
|
+
signMessage(message: Uint8Array): Promise<Signature>;
|
|
883
953
|
}
|
|
884
954
|
|
|
885
955
|
/**
|
|
886
|
-
*
|
|
956
|
+
* Signer implementation using a local Ed25519 keypair.
|
|
957
|
+
*
|
|
958
|
+
* Provides synchronous signing without external dependencies.
|
|
959
|
+
* Suitable for server-side applications, CLIs, and testing.
|
|
960
|
+
*
|
|
961
|
+
* @example
|
|
962
|
+
* ```typescript
|
|
963
|
+
* import { Keypair, KeypairSigner } from '@rialo/ts-cdk';
|
|
964
|
+
*
|
|
965
|
+
* // Generate new keypair
|
|
966
|
+
* const keypair = Keypair.generate();
|
|
967
|
+
* const signer = new KeypairSigner(keypair);
|
|
968
|
+
*
|
|
969
|
+
* // Or from mnemonic
|
|
970
|
+
* const mnemonic = Mnemonic.generate();
|
|
971
|
+
* const keypair = await mnemonic.toKeypair(0);
|
|
972
|
+
* const signer = new KeypairSigner(keypair);
|
|
973
|
+
*
|
|
974
|
+
* // Sign messages
|
|
975
|
+
* const publicKey = await signer.getPublicKey();
|
|
976
|
+
* const signature = await signer.signMessage(message);
|
|
977
|
+
* ```
|
|
887
978
|
*/
|
|
979
|
+
declare class KeypairSigner implements Signer {
|
|
980
|
+
private readonly keypair;
|
|
981
|
+
constructor(keypair: Keypair);
|
|
982
|
+
/**
|
|
983
|
+
* Returns the keypair's public key.
|
|
984
|
+
*/
|
|
985
|
+
getPublicKey(): Promise<PublicKey>;
|
|
986
|
+
/**
|
|
987
|
+
* Signs a message using the keypair's private key.
|
|
988
|
+
*/
|
|
989
|
+
signMessage(message: Uint8Array): Promise<Signature>;
|
|
990
|
+
}
|
|
888
991
|
|
|
889
992
|
/**
|
|
890
|
-
*
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
993
|
+
* A transaction with zero or more signatures.
|
|
994
|
+
*
|
|
995
|
+
* Transactions are immutable - signing methods return new instances.
|
|
996
|
+
* This prevents accidental modification and signature tampering.
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* ```typescript
|
|
1000
|
+
* // Simple signing
|
|
1001
|
+
* const tx = builder.build();
|
|
1002
|
+
* const signed = tx.sign(keypair);
|
|
1003
|
+
*
|
|
1004
|
+
* // Method chaining
|
|
1005
|
+
* const signed = tx
|
|
1006
|
+
* .sign(keypair1)
|
|
1007
|
+
* .sign(keypair2)
|
|
1008
|
+
* .sign(keypair3);
|
|
1009
|
+
*
|
|
1010
|
+
* // Multi-sig convenience
|
|
1011
|
+
* const signed = tx.signAll([keypair1, keypair2, keypair3]);
|
|
1012
|
+
* ```
|
|
1013
|
+
*/
|
|
1014
|
+
declare class Transaction {
|
|
1015
|
+
/** The unsigned message */
|
|
1016
|
+
private readonly message;
|
|
1017
|
+
/** Signatures (64 bytes each), aligned with message.header.numRequiredSignatures */
|
|
1018
|
+
private readonly signatures;
|
|
1019
|
+
private constructor();
|
|
1020
|
+
/**
|
|
1021
|
+
* Create an unsigned transaction from a message.
|
|
1022
|
+
* All signature slots are initialized to zero.
|
|
1023
|
+
*
|
|
1024
|
+
* @internal - Users should use TransactionBuilder instead
|
|
1025
|
+
*/
|
|
1026
|
+
static fromMessage(message: Message): Transaction;
|
|
1027
|
+
/**
|
|
1028
|
+
* Create transaction from message and existing signatures.
|
|
1029
|
+
* @internal
|
|
1030
|
+
*/
|
|
1031
|
+
static fromMessageAndSignatures(message: Message, signatures: readonly Uint8Array[]): Transaction;
|
|
1032
|
+
/**
|
|
1033
|
+
* Deserialize a transaction from wire format.
|
|
1034
|
+
*/
|
|
1035
|
+
static deserialize(data: Uint8Array): Transaction;
|
|
1036
|
+
getMessage(): Message;
|
|
1037
|
+
/**
|
|
1038
|
+
* Sign the transaction with a keypair.
|
|
1039
|
+
* Returns a NEW Transaction instance.
|
|
1040
|
+
*
|
|
1041
|
+
* @param keypair - Keypair to sign with
|
|
1042
|
+
* @returns New Transaction instance with signature added
|
|
1043
|
+
*
|
|
1044
|
+
* @example
|
|
1045
|
+
* ```typescript
|
|
1046
|
+
* const signedTx = tx.sign(keypair);
|
|
1047
|
+
* await client.sendTransaction(signedTx.serialize());
|
|
1048
|
+
* ```
|
|
1049
|
+
*/
|
|
1050
|
+
sign(keypair: Keypair): Transaction;
|
|
1051
|
+
/**
|
|
1052
|
+
* Sign with multiple keypairs at once.
|
|
1053
|
+
* Returns a NEW Transaction instance.
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```typescript
|
|
1057
|
+
* const signed = tx.signAll([keypair1, keypair2, keypair3]);
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
signAll(keypairs: Keypair[]): Transaction;
|
|
1061
|
+
/**
|
|
1062
|
+
* Sign the transaction with a Signer interface (async).
|
|
1063
|
+
* Returns a NEW Transaction instance.
|
|
1064
|
+
*
|
|
1065
|
+
* @example
|
|
1066
|
+
* ```typescript
|
|
1067
|
+
* const signedTx = await tx.signWith(browserWallet);
|
|
1068
|
+
* ```
|
|
1069
|
+
*/
|
|
1070
|
+
signWith(signer: Signer): Promise<Transaction>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Sign with multiple signers.
|
|
1073
|
+
* Returns a NEW Transaction instance.
|
|
1074
|
+
*/
|
|
1075
|
+
signAllWith(signers: Signer[]): Promise<Transaction>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Partially sign the transaction (for multi-sig transactions).
|
|
1078
|
+
* Returns a NEW Transaction instance.
|
|
1079
|
+
*
|
|
1080
|
+
* @example
|
|
1081
|
+
* ```typescript
|
|
1082
|
+
* const signedTx = tx
|
|
1083
|
+
* .partialSign(signer1)
|
|
1084
|
+
* .partialSign(signer2);
|
|
1085
|
+
* ```
|
|
1086
|
+
*/
|
|
1087
|
+
partialSign(keypair: Keypair): Transaction;
|
|
1088
|
+
/**
|
|
1089
|
+
* Partially sign with a Signer interface (async).
|
|
1090
|
+
* Returns a NEW Transaction instance.
|
|
1091
|
+
*/
|
|
1092
|
+
partialSignWith(signer: Signer): Promise<Transaction>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Add a signature at a specific index.
|
|
1095
|
+
* Returns a NEW Transaction instance.
|
|
1096
|
+
*
|
|
1097
|
+
* Most users should use sign() or signAll() instead.
|
|
1098
|
+
*/
|
|
1099
|
+
addSignature(index: number, signature: Signature | Uint8Array): Transaction;
|
|
1100
|
+
/**
|
|
1101
|
+
* Add a signature for a specific public key.
|
|
1102
|
+
* Returns a NEW Transaction instance.
|
|
1103
|
+
*
|
|
1104
|
+
* Most users should use sign() or signAll() instead.
|
|
1105
|
+
*/
|
|
1106
|
+
addSignatureForPubkey(pubkey: PublicKey, signature: Signature | Uint8Array): Transaction;
|
|
1107
|
+
/**
|
|
1108
|
+
* Check if transaction is fully signed (all signatures present).
|
|
1109
|
+
*/
|
|
1110
|
+
isSigned(): boolean;
|
|
1111
|
+
/**
|
|
1112
|
+
* Check if a specific signature slot is filled.
|
|
1113
|
+
*/
|
|
1114
|
+
isSignaturePresent(index: number): boolean;
|
|
1115
|
+
/**
|
|
1116
|
+
* Get all signatures (returns copies to prevent mutation).
|
|
1117
|
+
*/
|
|
1118
|
+
getSignatures(): readonly Uint8Array[];
|
|
1119
|
+
/**
|
|
1120
|
+
* Get a specific signature (returns copy).
|
|
1121
|
+
*/
|
|
1122
|
+
getSignature(index: number): Uint8Array;
|
|
1123
|
+
/**
|
|
1124
|
+
* Get a specific signature for a public key.
|
|
1125
|
+
*/
|
|
1126
|
+
getSignatureForPubkey(pubkey: PublicKey): Uint8Array;
|
|
1127
|
+
/**
|
|
1128
|
+
* Get required signers for this transaction.
|
|
1129
|
+
*/
|
|
1130
|
+
getSigners(): readonly PublicKey[];
|
|
1131
|
+
/**
|
|
1132
|
+
* Get the number of required signatures.
|
|
1133
|
+
*/
|
|
1134
|
+
getRequiredSignatureCount(): number;
|
|
1135
|
+
/**
|
|
1136
|
+
* Throw an error if the transaction is not fully signed.
|
|
1137
|
+
*
|
|
1138
|
+
* @throws {TransactionError} If transaction is not fully signed
|
|
1139
|
+
*
|
|
1140
|
+
* @example
|
|
1141
|
+
* ```typescript
|
|
1142
|
+
* signedTx.ensureSigned(); // Throws if not signed
|
|
1143
|
+
* await client.sendTransaction(signedTx.serialize());
|
|
1144
|
+
* ```
|
|
1145
|
+
*/
|
|
1146
|
+
ensureSigned(): void;
|
|
1147
|
+
/**
|
|
1148
|
+
* Serialize transaction to wire format.
|
|
1149
|
+
*/
|
|
1150
|
+
serialize(): Uint8Array;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Fluent API for building transactions.
|
|
1155
|
+
* Returns Transaction directly (not Message).
|
|
1156
|
+
*/
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* Builder for creating transactions with a fluent API.
|
|
1160
|
+
*
|
|
1161
|
+
* Provides an intuitive interface for constructing transactions.
|
|
1162
|
+
* Call build() to get an unsigned Transaction ready for signing.
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* ```typescript
|
|
1166
|
+
* // Simple transfer
|
|
1167
|
+
* const tx = TransactionBuilder.create()
|
|
1168
|
+
* .setPayer(payer)
|
|
1169
|
+
* .setValidFrom(validFrom)
|
|
1170
|
+
* .addInstruction(transfer(from, to, 1_000_000n))
|
|
1171
|
+
* .build();
|
|
1172
|
+
*
|
|
1173
|
+
* const signedTx = tx.sign(keypair);
|
|
1174
|
+
* await client.transaction.sendTransaction(signedTx.serialize());
|
|
1175
|
+
* ```
|
|
1176
|
+
*
|
|
1177
|
+
* @example
|
|
1178
|
+
* ```typescript
|
|
1179
|
+
* // Multi-instruction transaction
|
|
1180
|
+
* const tx = TransactionBuilder.create()
|
|
1181
|
+
* .setPayer(payer)
|
|
1182
|
+
* .setValidFrom(validFrom)
|
|
1183
|
+
* .addInstruction(transfer(from, to, 1_000_000n))
|
|
1184
|
+
* .addInstruction(memoInstruction("Payment for invoice #123"))
|
|
1185
|
+
* .build();
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
declare class TransactionBuilder {
|
|
1189
|
+
private payer?;
|
|
1190
|
+
private validFrom?;
|
|
1191
|
+
private readonly instructions;
|
|
1192
|
+
private constructor();
|
|
1193
|
+
/**
|
|
1194
|
+
* Create a new transaction builder.
|
|
1195
|
+
*/
|
|
1196
|
+
static create(): TransactionBuilder;
|
|
1197
|
+
/**
|
|
1198
|
+
* Set the fee payer for this transaction.
|
|
1199
|
+
*
|
|
1200
|
+
* The payer will be the first account and must sign the transaction.
|
|
1201
|
+
* The payer pays for transaction fees.
|
|
1202
|
+
*
|
|
1203
|
+
* @param payer - Public key of the fee payer
|
|
1204
|
+
*/
|
|
1205
|
+
setPayer(payer: PublicKey): this;
|
|
1206
|
+
/**
|
|
1207
|
+
* Set the Transaction valid from.
|
|
1208
|
+
*
|
|
1209
|
+
* This is the time the transaction is valid from, in milliseconds since Unix epoch.
|
|
1210
|
+
* It can be used for additional replay protection or auditing.
|
|
1211
|
+
*
|
|
1212
|
+
* @param validFrom - Transaction valid from in milliseconds since Unix epoch
|
|
1213
|
+
*/
|
|
1214
|
+
setValidFrom(validFrom: bigint): this;
|
|
1215
|
+
/**
|
|
1216
|
+
* Add an instruction to the transaction.
|
|
1217
|
+
*
|
|
1218
|
+
* @param instruction - Instruction to add
|
|
1219
|
+
*/
|
|
1220
|
+
addInstruction(instruction: Instruction): this;
|
|
1221
|
+
/**
|
|
1222
|
+
* Add multiple instructions at once.
|
|
1223
|
+
*
|
|
1224
|
+
* @param instructions - Array of instructions to add
|
|
1225
|
+
*/
|
|
1226
|
+
addInstructions(instructions: readonly Instruction[]): this;
|
|
1227
|
+
/**
|
|
1228
|
+
* Build the transaction (unsigned).
|
|
1229
|
+
*
|
|
1230
|
+
* Returns an unsigned Transaction that's ready to be signed.
|
|
1231
|
+
*
|
|
1232
|
+
* @returns Unsigned Transaction
|
|
1233
|
+
* @throws {TransactionError} If payer, valid_from, or instructions are missing
|
|
1234
|
+
*
|
|
1235
|
+
* @example
|
|
1236
|
+
* ```typescript
|
|
1237
|
+
* const tx = builder.build();
|
|
1238
|
+
* const signedTx = tx.sign(keypair);
|
|
1239
|
+
* ```
|
|
1240
|
+
*/
|
|
1241
|
+
build(): Transaction;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* Base client with JSON-RPC protocol handling.
|
|
1246
|
+
*
|
|
1247
|
+
* All specific clients (QueryClient, TransactionClient) extend this.
|
|
1248
|
+
*/
|
|
1249
|
+
declare class BaseRpcClient {
|
|
1250
|
+
protected readonly transport: HttpTransport;
|
|
1251
|
+
private requestId;
|
|
1252
|
+
constructor(transport: HttpTransport);
|
|
1253
|
+
/**
|
|
1254
|
+
* Makes a JSON-RPC 2.0 method call with type safety.
|
|
1255
|
+
*
|
|
1256
|
+
* Handles request serialization, response validation, and error mapping.
|
|
1257
|
+
*/
|
|
1258
|
+
protected call<T>(method: string, params?: unknown[]): Promise<T>;
|
|
1259
|
+
/**
|
|
1260
|
+
* Validate JSON-RPC response structure
|
|
1261
|
+
*/
|
|
1262
|
+
private isValidJsonRpcResponse;
|
|
1263
|
+
/**
|
|
1264
|
+
* Generates the next request ID with Overflow Protection.
|
|
1265
|
+
* @returns The next request ID.
|
|
1266
|
+
*/
|
|
1267
|
+
private nextRequestId;
|
|
1268
|
+
/**
|
|
1269
|
+
* Returns the configured RPC endpoint URL.
|
|
1270
|
+
*/
|
|
1271
|
+
getUrl(): string;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* RPC type definitions for the Rialo blockchain.
|
|
1276
|
+
*/
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* Account information response.
|
|
1280
|
+
*/
|
|
1281
|
+
interface AccountInfo {
|
|
1282
|
+
/** Account balance in smallest denomination */
|
|
894
1283
|
balance: bigint;
|
|
895
1284
|
/** Owner program public key */
|
|
896
1285
|
owner: PublicKey;
|
|
@@ -907,21 +1296,8 @@ interface AccountInfo {
|
|
|
907
1296
|
interface TransactionResponse {
|
|
908
1297
|
/** Transaction signature */
|
|
909
1298
|
signature: string;
|
|
910
|
-
/**
|
|
911
|
-
|
|
912
|
-
/** Block time (Unix timestamp) */
|
|
913
|
-
blockTime?: bigint;
|
|
914
|
-
/** Error message if transaction failed */
|
|
915
|
-
err?: string;
|
|
916
|
-
}
|
|
917
|
-
/**
|
|
918
|
-
* Signature status.
|
|
919
|
-
*/
|
|
920
|
-
interface SignatureStatus {
|
|
921
|
-
/** Slot in which the transaction was processed */
|
|
922
|
-
slot: bigint;
|
|
923
|
-
/** Number of confirmations */
|
|
924
|
-
confirmations?: number;
|
|
1299
|
+
/** Block height */
|
|
1300
|
+
blockHeight?: bigint;
|
|
925
1301
|
/** Error message if transaction failed */
|
|
926
1302
|
err?: string;
|
|
927
1303
|
}
|
|
@@ -1060,673 +1436,574 @@ interface GetTransactionsResponse {
|
|
|
1060
1436
|
/** Array of transaction data */
|
|
1061
1437
|
transactions: Array<Record<string, unknown>>;
|
|
1062
1438
|
}
|
|
1063
|
-
|
|
1064
1439
|
/**
|
|
1065
|
-
*
|
|
1440
|
+
* Signature status from the RPC.
|
|
1066
1441
|
*/
|
|
1067
|
-
|
|
1068
|
-
/**
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
*
|
|
1075
|
-
* @example
|
|
1076
|
-
* ```typescript
|
|
1077
|
-
* const client = createRialoClient(URL_DEVNET);
|
|
1078
|
-
*
|
|
1079
|
-
* // Query operations
|
|
1080
|
-
* const balance = await client.getBalance(publicKey);
|
|
1081
|
-
* const blockhash = await client.getLatestBlockhash();
|
|
1082
|
-
*
|
|
1083
|
-
* // Transaction operations
|
|
1084
|
-
* const signature = await client.sendTransaction(signedTx);
|
|
1085
|
-
* ```
|
|
1086
|
-
*/
|
|
1087
|
-
declare class RialoClient {
|
|
1088
|
-
private readonly queryClient;
|
|
1089
|
-
private readonly transactionClient;
|
|
1090
|
-
private readonly transport;
|
|
1091
|
-
constructor(transport: HttpTransport);
|
|
1092
|
-
/**
|
|
1093
|
-
* Returns the configured RPC endpoint URL.
|
|
1094
|
-
*/
|
|
1095
|
-
getUrl(): string;
|
|
1096
|
-
/**
|
|
1097
|
-
* Retrieves the latest blockhash from the blockchain.
|
|
1098
|
-
*
|
|
1099
|
-
* Required for transaction creation and replay protection.
|
|
1100
|
-
*/
|
|
1101
|
-
getLatestBlockhash(): Promise<Blockhash>;
|
|
1102
|
-
/**
|
|
1103
|
-
* Retrieves the balance of an account in kelvins (smallest unit).
|
|
1104
|
-
*/
|
|
1105
|
-
getBalance(pubkey: PublicKey): Promise<bigint>;
|
|
1106
|
-
/**
|
|
1107
|
-
* Retrieves detailed information about an account.
|
|
1108
|
-
*
|
|
1109
|
-
* @returns Account info or null if account doesn't exist
|
|
1110
|
-
*/
|
|
1111
|
-
getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
|
|
1112
|
-
/**
|
|
1113
|
-
* Retrieves the current block height.
|
|
1114
|
-
*/
|
|
1115
|
-
getBlockHeight(): Promise<bigint>;
|
|
1116
|
-
/**
|
|
1117
|
-
* Retrieves detailed information about a transaction.
|
|
1118
|
-
*
|
|
1119
|
-
* @returns Transaction info or null if transaction not found
|
|
1120
|
-
*/
|
|
1121
|
-
getTransaction(signature: string): Promise<TransactionResponse | null>;
|
|
1122
|
-
/**
|
|
1123
|
-
* Retrieves the total number of transactions processed since genesis.
|
|
1124
|
-
*/
|
|
1125
|
-
getTransactionCount(): Promise<bigint>;
|
|
1126
|
-
/**
|
|
1127
|
-
* Retrieves the status of multiple transaction signatures.
|
|
1128
|
-
*/
|
|
1129
|
-
getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
|
|
1130
|
-
/**
|
|
1131
|
-
* Retrieves current epoch information.
|
|
1132
|
-
*/
|
|
1133
|
-
getEpochInfo(): Promise<EpochInfoResponse>;
|
|
1134
|
-
/**
|
|
1135
|
-
* Checks the health status of the RPC node.
|
|
1136
|
-
*
|
|
1137
|
-
* @returns "ok" if healthy, error message otherwise
|
|
1138
|
-
*/
|
|
1139
|
-
getHealth(): Promise<"ok" | string>;
|
|
1140
|
-
/**
|
|
1141
|
-
* Submits a signed transaction to the blockchain.
|
|
1142
|
-
*
|
|
1143
|
-
* @param transaction - Serialized signed transaction bytes
|
|
1144
|
-
* @param options - Transaction submission options
|
|
1145
|
-
* @returns Transaction signature
|
|
1146
|
-
*/
|
|
1147
|
-
sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
|
|
1148
|
-
/**
|
|
1149
|
-
* Requests an airdrop of tokens to an account.
|
|
1150
|
-
*
|
|
1151
|
-
* **Note**: Only available on devnet and testnet.
|
|
1152
|
-
*
|
|
1153
|
-
* @param pubkey - Account to receive the airdrop
|
|
1154
|
-
* @param amount - Amount in kelvins (smallest unit)
|
|
1155
|
-
* @returns Transaction signature
|
|
1156
|
-
*/
|
|
1157
|
-
requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
/**
|
|
1161
|
-
* Query client for read-only RPC operations.
|
|
1162
|
-
*/
|
|
1163
|
-
|
|
1164
|
-
/**
|
|
1165
|
-
* Client for querying blockchain state.
|
|
1166
|
-
*
|
|
1167
|
-
* Handles all read-only operations like getting balances, account info, etc.
|
|
1168
|
-
*/
|
|
1169
|
-
declare class QueryRpcClient extends BaseRpcClient {
|
|
1170
|
-
/**
|
|
1171
|
-
* Get the latest blockhash from the blockchain
|
|
1172
|
-
*/
|
|
1173
|
-
getLatestBlockhash(): Promise<Blockhash>;
|
|
1174
|
-
/**
|
|
1175
|
-
* Get the balance of an account
|
|
1176
|
-
*/
|
|
1177
|
-
getBalance(pubkey: PublicKey): Promise<bigint>;
|
|
1178
|
-
/**
|
|
1179
|
-
* Get detailed information about an account
|
|
1180
|
-
*/
|
|
1181
|
-
getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
|
|
1182
|
-
/**
|
|
1183
|
-
* Get the current block height
|
|
1184
|
-
*/
|
|
1185
|
-
getBlockHeight(): Promise<bigint>;
|
|
1186
|
-
/**
|
|
1187
|
-
* Get detailed information about a transaction
|
|
1188
|
-
*/
|
|
1189
|
-
getTransaction(signature: string): Promise<TransactionResponse | null>;
|
|
1190
|
-
/**
|
|
1191
|
-
* Get the total number of transactions processed since genesis
|
|
1192
|
-
*/
|
|
1193
|
-
getTransactionCount(): Promise<bigint>;
|
|
1194
|
-
/**
|
|
1195
|
-
* Get the status of multiple transaction signatures
|
|
1196
|
-
*/
|
|
1197
|
-
getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
|
|
1198
|
-
/**
|
|
1199
|
-
* Get epoch information
|
|
1200
|
-
*/
|
|
1201
|
-
getEpochInfo(): Promise<EpochInfoResponse>;
|
|
1202
|
-
/**
|
|
1203
|
-
* Get the health status of the node
|
|
1204
|
-
*/
|
|
1205
|
-
getHealth(): Promise<"ok" | string>;
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
/**
|
|
1209
|
-
* Query client for read-only RPC operations.
|
|
1210
|
-
*/
|
|
1211
|
-
|
|
1212
|
-
/**
|
|
1213
|
-
* Client for sending/simulating transactions and requesting airdrops.
|
|
1214
|
-
*
|
|
1215
|
-
* Handles all transaction operations like sending transactions, requesting airdrops, etc.
|
|
1216
|
-
*/
|
|
1217
|
-
declare class TransactionRpcClient extends BaseRpcClient {
|
|
1218
|
-
/**
|
|
1219
|
-
* Submit a signed transaction to the blockchain
|
|
1220
|
-
*/
|
|
1221
|
-
sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
|
|
1222
|
-
/**
|
|
1223
|
-
* Request an airdrop of tokens to an account (devnet/testnet only)
|
|
1224
|
-
*/
|
|
1225
|
-
requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
|
|
1442
|
+
interface SignatureStatus {
|
|
1443
|
+
/** Slot in which the transaction was processed */
|
|
1444
|
+
slot: bigint;
|
|
1445
|
+
/** Whether the transaction has been executed */
|
|
1446
|
+
executed: boolean;
|
|
1447
|
+
/** Error message if transaction failed */
|
|
1448
|
+
err?: string;
|
|
1226
1449
|
}
|
|
1227
|
-
|
|
1228
1450
|
/**
|
|
1229
|
-
*
|
|
1451
|
+
* Options for confirming a transaction.
|
|
1230
1452
|
*/
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
PARSE_ERROR = "PARSE_ERROR",
|
|
1237
|
-
INVALID_REQUEST = "INVALID_REQUEST",
|
|
1238
|
-
METHOD_NOT_FOUND = "METHOD_NOT_FOUND",
|
|
1239
|
-
INVALID_PARAMS = "INVALID_PARAMS",
|
|
1240
|
-
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
1241
|
-
TRANSACTION_REJECTED = "TRANSACTION_REJECTED",
|
|
1242
|
-
INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
|
|
1243
|
-
ACCOUNT_NOT_FOUND = "ACCOUNT_NOT_FOUND",
|
|
1244
|
-
BLOCKHASH_NOT_FOUND = "BLOCKHASH_NOT_FOUND",
|
|
1245
|
-
RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
|
|
1246
|
-
NODE_UNHEALTHY = "NODE_UNHEALTHY"
|
|
1453
|
+
interface ConfirmTransactionOptions {
|
|
1454
|
+
/** Maximum number of retry attempts (default: 30) */
|
|
1455
|
+
maxRetries?: number;
|
|
1456
|
+
/** Delay between retries in milliseconds (default: 1000) */
|
|
1457
|
+
retryDelay?: number;
|
|
1247
1458
|
}
|
|
1248
1459
|
/**
|
|
1249
|
-
*
|
|
1460
|
+
* Options for sending and confirming a transaction.
|
|
1250
1461
|
*/
|
|
1251
|
-
interface
|
|
1252
|
-
method?: string;
|
|
1253
|
-
params?: unknown;
|
|
1254
|
-
requestId?: number;
|
|
1255
|
-
url?: string;
|
|
1256
|
-
httpStatus?: number;
|
|
1257
|
-
rpcCode?: number;
|
|
1258
|
-
timeout?: number;
|
|
1259
|
-
attempts?: number;
|
|
1260
|
-
[key: string]: unknown;
|
|
1462
|
+
interface SendAndConfirmOptions extends SendTransactionOptions, ConfirmTransactionOptions {
|
|
1261
1463
|
}
|
|
1262
1464
|
/**
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
* Provides actionable error messages and indicates whether errors are retryable.
|
|
1465
|
+
* Result of a confirmed transaction.
|
|
1266
1466
|
*/
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
static invalidResponse(details: RpcErrorDetails): RpcError;
|
|
1275
|
-
static accountNotFound(pubkey: string): RpcError;
|
|
1276
|
-
static rateLimitExceeded(details: RpcErrorDetails): RpcError;
|
|
1277
|
-
static fromRpcCode(rpcCode: number, message: string, details: RpcErrorDetails): RpcError;
|
|
1278
|
-
toJSON(): {
|
|
1279
|
-
code: RpcErrorCode;
|
|
1280
|
-
message: string;
|
|
1281
|
-
details?: Record<string, unknown>;
|
|
1282
|
-
retryable: boolean;
|
|
1283
|
-
};
|
|
1467
|
+
interface ConfirmedTransaction {
|
|
1468
|
+
/** Transaction signature */
|
|
1469
|
+
signature: string;
|
|
1470
|
+
/** Whether the transaction was executed */
|
|
1471
|
+
executed: boolean;
|
|
1472
|
+
/** Error message if transaction failed */
|
|
1473
|
+
err?: string;
|
|
1284
1474
|
}
|
|
1285
1475
|
|
|
1286
1476
|
/**
|
|
1287
|
-
* RPC client
|
|
1477
|
+
* Main Rialo RPC client for blockchain interactions.
|
|
1478
|
+
*/
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* High-level Rialo RPC client for blockchain interactions.
|
|
1288
1482
|
*
|
|
1289
|
-
* Provides a
|
|
1290
|
-
*
|
|
1483
|
+
* Provides a unified interface for querying blockchain state and
|
|
1484
|
+
* sending transactions. Internally delegates to specialized clients
|
|
1485
|
+
* (QueryRpcClient, TransactionRpcClient) for modular organization.
|
|
1291
1486
|
*
|
|
1292
1487
|
* @example
|
|
1293
1488
|
* ```typescript
|
|
1294
|
-
* import { createRialoClient,
|
|
1489
|
+
* import { createRialoClient, RIALO_DEVNET_CHAIN } from '@rialo/ts-cdk';
|
|
1295
1490
|
*
|
|
1296
|
-
*
|
|
1297
|
-
* const client = createRialoClient(URL_DEVNET, {
|
|
1298
|
-
* timeout: 30000,
|
|
1299
|
-
* maxRetries: 3,
|
|
1300
|
-
* });
|
|
1491
|
+
* const client = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
|
|
1301
1492
|
*
|
|
1302
|
-
* // Query
|
|
1493
|
+
* // Query operations
|
|
1303
1494
|
* const balance = await client.getBalance(publicKey);
|
|
1304
|
-
* const
|
|
1495
|
+
* const chainId = client.getChainIdentifier();
|
|
1305
1496
|
*
|
|
1306
|
-
* //
|
|
1497
|
+
* // Transaction operations
|
|
1307
1498
|
* const signature = await client.sendTransaction(signedTx);
|
|
1308
1499
|
* ```
|
|
1309
1500
|
*/
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
* @returns Configured RialoClient instance
|
|
1317
|
-
*/
|
|
1318
|
-
declare function createRialoClient(url: string, config?: HttpTransportConfig): RialoClient;
|
|
1319
|
-
|
|
1320
|
-
/**
|
|
1321
|
-
* An unsigned transaction message ready to be signed.
|
|
1322
|
-
*
|
|
1323
|
-
* This is the data that gets signed by transaction signers.
|
|
1324
|
-
* It's immutable to prevent accidental modification after creation.
|
|
1325
|
-
*
|
|
1326
|
-
* @example
|
|
1327
|
-
* ```typescript
|
|
1328
|
-
* const message = MessageBuilder.create()
|
|
1329
|
-
* .setPayer(payer)
|
|
1330
|
-
* .setRecentBlockhash(blockhash)
|
|
1331
|
-
* .setCreationTime(txCreationTime)
|
|
1332
|
-
* .addInstruction(transferInstruction)
|
|
1333
|
-
* .build();
|
|
1334
|
-
*
|
|
1335
|
-
* // Serialize for signing
|
|
1336
|
-
* const messageBytes = message.serialize();
|
|
1337
|
-
* ```
|
|
1338
|
-
*/
|
|
1339
|
-
declare class Message {
|
|
1340
|
-
/** Message header with signature requirements */
|
|
1341
|
-
readonly header: MessageHeader;
|
|
1342
|
-
/** All account public keys referenced in the transaction */
|
|
1343
|
-
readonly accountKeys: readonly PublicKey[];
|
|
1344
|
-
/** Recent blockhash for replay protection */
|
|
1345
|
-
readonly recentBlockhash: Blockhash;
|
|
1346
|
-
/** Transaction creation timestamp (milliseconds since Unix epoch) */
|
|
1347
|
-
txCreationTime?: bigint;
|
|
1348
|
-
/** Compiled instructions with account indices */
|
|
1349
|
-
readonly instructions: readonly CompiledInstruction[];
|
|
1350
|
-
/** Cached serialized bytes */
|
|
1351
|
-
private serializedCache?;
|
|
1352
|
-
constructor(header: MessageHeader, accountKeys: readonly PublicKey[], recentBlockhash: Blockhash, txCreationTime: bigint, instructions: readonly CompiledInstruction[]);
|
|
1501
|
+
declare class RialoClient {
|
|
1502
|
+
private readonly queryClient;
|
|
1503
|
+
private readonly transactionClient;
|
|
1504
|
+
private readonly transport;
|
|
1505
|
+
private readonly chain;
|
|
1506
|
+
constructor(transport: HttpTransport, chain: ChainDefinition);
|
|
1353
1507
|
/**
|
|
1354
|
-
*
|
|
1355
|
-
* Result is cached for performance.
|
|
1508
|
+
* Returns the configured RPC endpoint URL.
|
|
1356
1509
|
*/
|
|
1357
|
-
|
|
1510
|
+
getUrl(): string;
|
|
1358
1511
|
/**
|
|
1359
|
-
*
|
|
1512
|
+
* Returns the chain identifier.
|
|
1513
|
+
*/
|
|
1514
|
+
getChainIdentifier(): IdentifierString;
|
|
1515
|
+
/**
|
|
1516
|
+
* Returns the chain configuration.
|
|
1517
|
+
*/
|
|
1518
|
+
getChainConfig(): ChainDefinition;
|
|
1519
|
+
/**
|
|
1520
|
+
* Retrieves the balance of an account in kelvins (smallest unit).
|
|
1521
|
+
*/
|
|
1522
|
+
getBalance(pubkey: PublicKey): Promise<bigint>;
|
|
1523
|
+
/**
|
|
1524
|
+
* Retrieves detailed information about an account.
|
|
1360
1525
|
*
|
|
1361
|
-
* @
|
|
1362
|
-
* @returns Deserialized Message
|
|
1526
|
+
* @returns Account info or null if account doesn't exist
|
|
1363
1527
|
*/
|
|
1364
|
-
|
|
1365
|
-
private serializeInternal;
|
|
1366
|
-
private serializeCompactArray;
|
|
1367
|
-
private serializeCompactU16;
|
|
1528
|
+
getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
|
|
1368
1529
|
/**
|
|
1369
|
-
*
|
|
1530
|
+
* Retrieves the current block height.
|
|
1370
1531
|
*/
|
|
1371
|
-
|
|
1532
|
+
getBlockHeight(): Promise<bigint>;
|
|
1372
1533
|
/**
|
|
1373
|
-
*
|
|
1534
|
+
* Retrieves detailed information about a transaction.
|
|
1535
|
+
*
|
|
1536
|
+
* @returns Transaction info or null if transaction not found
|
|
1374
1537
|
*/
|
|
1375
|
-
|
|
1538
|
+
getTransaction(signature: string): Promise<TransactionResponse | null>;
|
|
1376
1539
|
/**
|
|
1377
|
-
*
|
|
1378
|
-
* Returns -1 if not a signer.
|
|
1540
|
+
* Retrieves the total number of transactions processed since genesis.
|
|
1379
1541
|
*/
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* Interface for signing messages and transactions.
|
|
1385
|
-
*
|
|
1386
|
-
* Enables multiple signing strategies:
|
|
1387
|
-
* - **KeypairSigner**: Local keypair signing
|
|
1388
|
-
* - **Browser Wallet**: Browser extension integration
|
|
1389
|
-
* - **Hardware Wallet**: Ledger, Trezor, etc.
|
|
1390
|
-
* - **Remote Signer**: API-based signing services
|
|
1391
|
-
*
|
|
1392
|
-
* @example
|
|
1393
|
-
* ```typescript
|
|
1394
|
-
* // Browser wallet implementation
|
|
1395
|
-
* class BrowserWalletSigner implements Signer {
|
|
1396
|
-
* async getPublicKey(): Promise<PublicKey> {
|
|
1397
|
-
* const pubkey = await window.rialoWallet.getPublicKey();
|
|
1398
|
-
* return PublicKey.fromString(pubkey);
|
|
1399
|
-
* }
|
|
1400
|
-
*
|
|
1401
|
-
* async signMessage(message: Uint8Array): Promise<Signature> {
|
|
1402
|
-
* const sig = await window.rialoWallet.signMessage(message);
|
|
1403
|
-
* return Signature.fromBytes(sig);
|
|
1404
|
-
* }
|
|
1405
|
-
* }
|
|
1406
|
-
*
|
|
1407
|
-
* // Usage
|
|
1408
|
-
* const signer = new BrowserWalletSigner();
|
|
1409
|
-
* const publicKey = await signer.getPublicKey();
|
|
1410
|
-
* const signature = await signer.signMessage(message);
|
|
1411
|
-
* ```
|
|
1412
|
-
*/
|
|
1413
|
-
interface Signer {
|
|
1542
|
+
getTransactionCount(): Promise<bigint>;
|
|
1414
1543
|
/**
|
|
1415
|
-
* Retrieves the
|
|
1544
|
+
* Retrieves the status of multiple transaction signatures.
|
|
1545
|
+
*/
|
|
1546
|
+
getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
|
|
1547
|
+
/**
|
|
1548
|
+
* Retrieves current epoch information.
|
|
1549
|
+
*/
|
|
1550
|
+
getEpochInfo(): Promise<EpochInfoResponse>;
|
|
1551
|
+
/**
|
|
1552
|
+
* Checks the health status of the RPC node.
|
|
1416
1553
|
*
|
|
1417
|
-
*
|
|
1554
|
+
* @returns "ok" if healthy, error message otherwise
|
|
1418
1555
|
*/
|
|
1419
|
-
|
|
1556
|
+
getHealth(): Promise<"ok" | string>;
|
|
1420
1557
|
/**
|
|
1421
|
-
*
|
|
1558
|
+
* Submits a signed transaction to the blockchain.
|
|
1422
1559
|
*
|
|
1423
|
-
* @param
|
|
1424
|
-
* @
|
|
1560
|
+
* @param transaction - Serialized signed transaction bytes
|
|
1561
|
+
* @param options - Transaction submission options
|
|
1562
|
+
* @returns Transaction signature
|
|
1425
1563
|
*/
|
|
1426
|
-
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
/**
|
|
1430
|
-
* Signer implementation using a local Ed25519 keypair.
|
|
1431
|
-
*
|
|
1432
|
-
* Provides synchronous signing without external dependencies.
|
|
1433
|
-
* Suitable for server-side applications, CLIs, and testing.
|
|
1434
|
-
*
|
|
1435
|
-
* @example
|
|
1436
|
-
* ```typescript
|
|
1437
|
-
* import { Keypair, KeypairSigner } from '@rialo/ts-cdk';
|
|
1438
|
-
*
|
|
1439
|
-
* // Generate new keypair
|
|
1440
|
-
* const keypair = Keypair.generate();
|
|
1441
|
-
* const signer = new KeypairSigner(keypair);
|
|
1442
|
-
*
|
|
1443
|
-
* // Or from mnemonic
|
|
1444
|
-
* const mnemonic = Mnemonic.generate();
|
|
1445
|
-
* const keypair = await mnemonic.toKeypair(0);
|
|
1446
|
-
* const signer = new KeypairSigner(keypair);
|
|
1447
|
-
*
|
|
1448
|
-
* // Sign messages
|
|
1449
|
-
* const publicKey = await signer.getPublicKey();
|
|
1450
|
-
* const signature = await signer.signMessage(message);
|
|
1451
|
-
* ```
|
|
1452
|
-
*/
|
|
1453
|
-
declare class KeypairSigner implements Signer {
|
|
1454
|
-
private readonly keypair;
|
|
1455
|
-
constructor(keypair: Keypair);
|
|
1564
|
+
sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
|
|
1456
1565
|
/**
|
|
1457
|
-
*
|
|
1566
|
+
* Requests an airdrop of tokens to an account.
|
|
1567
|
+
*
|
|
1568
|
+
* **Note**: Only available on devnet and testnet.
|
|
1569
|
+
*
|
|
1570
|
+
* @param pubkey - Account to receive the airdrop
|
|
1571
|
+
* @param amount - Amount in kelvins (smallest unit)
|
|
1572
|
+
* @returns Transaction signature
|
|
1458
1573
|
*/
|
|
1459
|
-
|
|
1574
|
+
requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
|
|
1460
1575
|
/**
|
|
1461
|
-
*
|
|
1576
|
+
* Submits a signed transaction and waits for confirmation.
|
|
1577
|
+
*
|
|
1578
|
+
* @param transaction - Serialized signed transaction bytes
|
|
1579
|
+
* @param options - Transaction submission and confirmation options
|
|
1580
|
+
* @returns Confirmed transaction details
|
|
1581
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
1582
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
1583
|
+
*
|
|
1584
|
+
* @example
|
|
1585
|
+
* ```typescript
|
|
1586
|
+
* const result = await client.sendAndConfirmTransaction(signedTx);
|
|
1587
|
+
* console.log(`Confirmed in slot ${result.slot}`);
|
|
1588
|
+
* ```
|
|
1462
1589
|
*/
|
|
1463
|
-
|
|
1590
|
+
sendAndConfirmTransaction(transaction: Uint8Array, options?: SendAndConfirmOptions): Promise<ConfirmedTransaction>;
|
|
1591
|
+
/**
|
|
1592
|
+
* Waits for a transaction to be confirmed.
|
|
1593
|
+
*
|
|
1594
|
+
* @param signature - Transaction signature to monitor
|
|
1595
|
+
* @param options - Confirmation options
|
|
1596
|
+
* @returns Confirmed transaction details
|
|
1597
|
+
*/
|
|
1598
|
+
confirmTransaction(signature: string, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
|
|
1599
|
+
/**
|
|
1600
|
+
* Requests an airdrop and waits for confirmation.
|
|
1601
|
+
*
|
|
1602
|
+
* **Note**: Only available on devnet and testnet.
|
|
1603
|
+
*/
|
|
1604
|
+
requestAirdropAndConfirm(pubkey: PublicKey, amount: bigint, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
|
|
1464
1605
|
}
|
|
1465
1606
|
|
|
1466
1607
|
/**
|
|
1467
|
-
*
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
*
|
|
1472
|
-
* @example
|
|
1473
|
-
* ```typescript
|
|
1474
|
-
* // Simple signing
|
|
1475
|
-
* const tx = builder.build();
|
|
1476
|
-
* const signed = tx.sign(keypair);
|
|
1477
|
-
*
|
|
1478
|
-
* // Method chaining
|
|
1479
|
-
* const signed = tx
|
|
1480
|
-
* .sign(keypair1)
|
|
1481
|
-
* .sign(keypair2)
|
|
1482
|
-
* .sign(keypair3);
|
|
1608
|
+
* Query client for read-only RPC operations.
|
|
1609
|
+
*/
|
|
1610
|
+
|
|
1611
|
+
/**
|
|
1612
|
+
* Client for querying blockchain state.
|
|
1483
1613
|
*
|
|
1484
|
-
*
|
|
1485
|
-
* const signed = tx.signAll([keypair1, keypair2, keypair3]);
|
|
1486
|
-
* ```
|
|
1614
|
+
* Handles all read-only operations like getting balances, account info, etc.
|
|
1487
1615
|
*/
|
|
1488
|
-
declare class
|
|
1489
|
-
/** The unsigned message */
|
|
1490
|
-
private readonly message;
|
|
1491
|
-
/** Signatures (64 bytes each), aligned with message.header.numRequiredSignatures */
|
|
1492
|
-
private readonly signatures;
|
|
1493
|
-
private constructor();
|
|
1616
|
+
declare class QueryRpcClient extends BaseRpcClient {
|
|
1494
1617
|
/**
|
|
1495
|
-
*
|
|
1496
|
-
* All signature slots are initialized to zero.
|
|
1618
|
+
* Retrieve the balance of an account in kelvins (smallest unit).
|
|
1497
1619
|
*
|
|
1498
|
-
* @
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
*
|
|
1503
|
-
*
|
|
1620
|
+
* @param pubkey - The public key of the account to query
|
|
1621
|
+
* @returns The account balance in kelvins
|
|
1622
|
+
*
|
|
1623
|
+
* @example
|
|
1624
|
+
* ```typescript
|
|
1625
|
+
* const balance = await client.getBalance(publicKey);
|
|
1626
|
+
* console.log(`Balance: ${balance} kelvins`);
|
|
1627
|
+
* ```
|
|
1504
1628
|
*/
|
|
1505
|
-
|
|
1629
|
+
getBalance(pubkey: PublicKey): Promise<bigint>;
|
|
1506
1630
|
/**
|
|
1507
|
-
*
|
|
1631
|
+
* Retrieve detailed information about an account.
|
|
1632
|
+
*
|
|
1633
|
+
* Returns account data including balance, owner program, stored data,
|
|
1634
|
+
* executable status, and rent epoch.
|
|
1635
|
+
*
|
|
1636
|
+
* @param pubkey - The public key of the account to query
|
|
1637
|
+
* @returns Account information, or null if the account does not exist
|
|
1638
|
+
*
|
|
1639
|
+
* @example
|
|
1640
|
+
* ```typescript
|
|
1641
|
+
* const info = await client.getAccountInfo(publicKey);
|
|
1642
|
+
* if (info) {
|
|
1643
|
+
* console.log(`Owner: ${info.owner}`);
|
|
1644
|
+
* console.log(`Balance: ${info.balance} kelvins`);
|
|
1645
|
+
* console.log(`Data length: ${info.data.length} bytes`);
|
|
1646
|
+
* }
|
|
1647
|
+
* ```
|
|
1508
1648
|
*/
|
|
1509
|
-
|
|
1510
|
-
getMessage(): Message;
|
|
1649
|
+
getAccountInfo(pubkey: PublicKey): Promise<AccountInfo | null>;
|
|
1511
1650
|
/**
|
|
1512
|
-
*
|
|
1513
|
-
*
|
|
1651
|
+
* Retrieve the current block height of the blockchain.
|
|
1652
|
+
*
|
|
1653
|
+
* The block height represents the number of blocks that have been
|
|
1654
|
+
* confirmed on the chain since genesis.
|
|
1514
1655
|
*
|
|
1515
|
-
* @
|
|
1516
|
-
* @returns New Transaction instance with signature added
|
|
1656
|
+
* @returns The current block height
|
|
1517
1657
|
*
|
|
1518
1658
|
* @example
|
|
1519
1659
|
* ```typescript
|
|
1520
|
-
* const
|
|
1521
|
-
*
|
|
1660
|
+
* const height = await client.getBlockHeight();
|
|
1661
|
+
* console.log(`Current block height: ${height}`);
|
|
1522
1662
|
* ```
|
|
1523
1663
|
*/
|
|
1524
|
-
|
|
1664
|
+
getBlockHeight(): Promise<bigint>;
|
|
1525
1665
|
/**
|
|
1526
|
-
*
|
|
1527
|
-
*
|
|
1666
|
+
* Retrieve detailed information about a confirmed transaction.
|
|
1667
|
+
*
|
|
1668
|
+
* Returns transaction metadata including the block height it was
|
|
1669
|
+
* confirmed in and any execution errors.
|
|
1670
|
+
*
|
|
1671
|
+
* @param signature - The transaction signature to query
|
|
1672
|
+
* @returns Transaction information, or null if the transaction is not found
|
|
1528
1673
|
*
|
|
1529
1674
|
* @example
|
|
1530
1675
|
* ```typescript
|
|
1531
|
-
* const
|
|
1676
|
+
* const tx = await client.getTransaction(signature);
|
|
1677
|
+
* if (tx) {
|
|
1678
|
+
* console.log(`Confirmed in block: ${tx.blockHeight}`);
|
|
1679
|
+
* if (tx.err) {
|
|
1680
|
+
* console.log(`Transaction failed: ${tx.err}`);
|
|
1681
|
+
* }
|
|
1682
|
+
* }
|
|
1532
1683
|
* ```
|
|
1533
1684
|
*/
|
|
1534
|
-
|
|
1685
|
+
getTransaction(signature: string): Promise<TransactionResponse | null>;
|
|
1535
1686
|
/**
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
1687
|
+
* Retrieve the total number of transactions processed since genesis.
|
|
1688
|
+
*
|
|
1689
|
+
* @returns The total transaction count
|
|
1538
1690
|
*
|
|
1539
1691
|
* @example
|
|
1540
1692
|
* ```typescript
|
|
1541
|
-
* const
|
|
1693
|
+
* const count = await client.getTransactionCount();
|
|
1694
|
+
* console.log(`Total transactions: ${count}`);
|
|
1542
1695
|
* ```
|
|
1543
1696
|
*/
|
|
1544
|
-
|
|
1545
|
-
/**
|
|
1546
|
-
* Sign with multiple signers.
|
|
1547
|
-
* Returns a NEW Transaction instance.
|
|
1548
|
-
*/
|
|
1549
|
-
signAllWith(signers: Signer[]): Promise<Transaction>;
|
|
1697
|
+
getTransactionCount(): Promise<bigint>;
|
|
1550
1698
|
/**
|
|
1551
|
-
*
|
|
1552
|
-
*
|
|
1699
|
+
* Retrieve the status of multiple transaction signatures in a single request.
|
|
1700
|
+
*
|
|
1701
|
+
* Useful for batch-checking transaction confirmations. Returns null for
|
|
1702
|
+
* signatures that are not found or have expired from the status cache.
|
|
1703
|
+
*
|
|
1704
|
+
* @param signatures - Array of transaction signatures to query
|
|
1705
|
+
* @returns Array of signature statuses (null if signature not found)
|
|
1553
1706
|
*
|
|
1554
1707
|
* @example
|
|
1555
1708
|
* ```typescript
|
|
1556
|
-
* const
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
1709
|
+
* const statuses = await client.getSignatureStatuses([sig1, sig2, sig3]);
|
|
1710
|
+
* statuses.forEach((status, i) => {
|
|
1711
|
+
* if (status) {
|
|
1712
|
+
* console.log(`${signatures[i]}: slot ${status.slot}, executed: ${status.executed}`);
|
|
1713
|
+
* } else {
|
|
1714
|
+
* console.log(`${signatures[i]}: not found`);
|
|
1715
|
+
* }
|
|
1716
|
+
* });
|
|
1559
1717
|
* ```
|
|
1560
1718
|
*/
|
|
1561
|
-
|
|
1562
|
-
/**
|
|
1563
|
-
* Partially sign with a Signer interface (async).
|
|
1564
|
-
* Returns a NEW Transaction instance.
|
|
1565
|
-
*/
|
|
1566
|
-
partialSignWith(signer: Signer): Promise<Transaction>;
|
|
1719
|
+
getSignatureStatuses(signatures: string[]): Promise<(SignatureStatus | null)[]>;
|
|
1567
1720
|
/**
|
|
1568
|
-
*
|
|
1569
|
-
* Returns a NEW Transaction instance.
|
|
1721
|
+
* Retrieve information about the current epoch.
|
|
1570
1722
|
*
|
|
1571
|
-
*
|
|
1572
|
-
|
|
1573
|
-
addSignature(index: number, signature: Signature | Uint8Array): Transaction;
|
|
1574
|
-
/**
|
|
1575
|
-
* Add a signature for a specific public key.
|
|
1576
|
-
* Returns a NEW Transaction instance.
|
|
1723
|
+
* Returns epoch metadata including the current epoch number, slot position
|
|
1724
|
+
* within the epoch, total slots per epoch, and current block height.
|
|
1577
1725
|
*
|
|
1578
|
-
*
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
*
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
*
|
|
1587
|
-
*/
|
|
1588
|
-
isSignaturePresent(index: number): boolean;
|
|
1589
|
-
/**
|
|
1590
|
-
* Get all signatures (returns copies to prevent mutation).
|
|
1591
|
-
*/
|
|
1592
|
-
getSignatures(): readonly Uint8Array[];
|
|
1593
|
-
/**
|
|
1594
|
-
* Get a specific signature (returns copy).
|
|
1595
|
-
*/
|
|
1596
|
-
getSignature(index: number): Uint8Array;
|
|
1597
|
-
/**
|
|
1598
|
-
* Get a specific signature for a public key.
|
|
1599
|
-
*/
|
|
1600
|
-
getSignatureForPubkey(pubkey: PublicKey): Uint8Array;
|
|
1601
|
-
/**
|
|
1602
|
-
* Get required signers for this transaction.
|
|
1603
|
-
*/
|
|
1604
|
-
getSigners(): readonly PublicKey[];
|
|
1605
|
-
/**
|
|
1606
|
-
* Get the number of required signatures.
|
|
1726
|
+
* @returns Current epoch information
|
|
1727
|
+
*
|
|
1728
|
+
* @example
|
|
1729
|
+
* ```typescript
|
|
1730
|
+
* const info = await client.getEpochInfo();
|
|
1731
|
+
* console.log(`Epoch: ${info.epoch}`);
|
|
1732
|
+
* console.log(`Slot ${info.slotIndex} of ${info.slotsInEpoch}`);
|
|
1733
|
+
* console.log(`Block height: ${info.blockHeight}`);
|
|
1734
|
+
* ```
|
|
1607
1735
|
*/
|
|
1608
|
-
|
|
1736
|
+
getEpochInfo(): Promise<EpochInfoResponse>;
|
|
1609
1737
|
/**
|
|
1610
|
-
*
|
|
1738
|
+
* Check the health status of the RPC node.
|
|
1611
1739
|
*
|
|
1612
|
-
*
|
|
1740
|
+
* Returns "ok" if the node is healthy. If the node is unhealthy,
|
|
1741
|
+
* returns an error message describing the issue.
|
|
1742
|
+
*
|
|
1743
|
+
* @returns "ok" if healthy, otherwise an error message
|
|
1613
1744
|
*
|
|
1614
1745
|
* @example
|
|
1615
1746
|
* ```typescript
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
1747
|
+
* const health = await client.getHealth();
|
|
1748
|
+
* if (health === "ok") {
|
|
1749
|
+
* console.log("Node is healthy");
|
|
1750
|
+
* } else {
|
|
1751
|
+
* console.log(`Node unhealthy: ${health}`);
|
|
1752
|
+
* }
|
|
1618
1753
|
* ```
|
|
1619
1754
|
*/
|
|
1620
|
-
|
|
1621
|
-
/**
|
|
1622
|
-
* Serialize transaction to wire format.
|
|
1623
|
-
*/
|
|
1624
|
-
serialize(): Uint8Array;
|
|
1755
|
+
getHealth(): Promise<"ok" | string>;
|
|
1625
1756
|
}
|
|
1626
1757
|
|
|
1627
1758
|
/**
|
|
1628
|
-
*
|
|
1629
|
-
* Returns Transaction directly (not Message).
|
|
1759
|
+
* Query client for read-only RPC operations.
|
|
1630
1760
|
*/
|
|
1631
1761
|
|
|
1632
1762
|
/**
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
1635
|
-
* Provides an intuitive interface for constructing transactions.
|
|
1636
|
-
* Call build() to get an unsigned Transaction ready for signing.
|
|
1637
|
-
*
|
|
1638
|
-
* @example
|
|
1639
|
-
* ```typescript
|
|
1640
|
-
* // Simple transfer
|
|
1641
|
-
* const tx = TransactionBuilder.create()
|
|
1642
|
-
* .setPayer(payer)
|
|
1643
|
-
* .setRecentBlockhash(blockhash)
|
|
1644
|
-
* .setTxCreationTime(txCreationTime)
|
|
1645
|
-
* .addInstruction(transfer(from, to, 1_000_000n))
|
|
1646
|
-
* .build();
|
|
1647
|
-
*
|
|
1648
|
-
* const signedTx = tx.sign(keypair);
|
|
1649
|
-
* await client.transaction.sendTransaction(signedTx.serialize());
|
|
1650
|
-
* ```
|
|
1763
|
+
* Client for sending/simulating transactions and requesting airdrops.
|
|
1651
1764
|
*
|
|
1652
|
-
*
|
|
1653
|
-
* ```typescript
|
|
1654
|
-
* // Multi-instruction transaction
|
|
1655
|
-
* const tx = TransactionBuilder.create()
|
|
1656
|
-
* .setPayer(payer)
|
|
1657
|
-
* .setRecentBlockhash(blockhash)
|
|
1658
|
-
* .setTxCreationTime(txCreationTime)
|
|
1659
|
-
* .addInstruction(transfer(from, to, 1_000_000n))
|
|
1660
|
-
* .addInstruction(memoInstruction("Payment for invoice #123"))
|
|
1661
|
-
* .build();
|
|
1662
|
-
* ```
|
|
1765
|
+
* Handles all transaction operations like sending transactions, requesting airdrops, etc.
|
|
1663
1766
|
*/
|
|
1664
|
-
declare class
|
|
1665
|
-
private payer?;
|
|
1666
|
-
private recentBlockhash?;
|
|
1667
|
-
private txCreationTime?;
|
|
1668
|
-
private readonly instructions;
|
|
1669
|
-
private constructor();
|
|
1670
|
-
/**
|
|
1671
|
-
* Create a new transaction builder.
|
|
1672
|
-
*/
|
|
1673
|
-
static create(): TransactionBuilder;
|
|
1767
|
+
declare class TransactionRpcClient extends BaseRpcClient {
|
|
1674
1768
|
/**
|
|
1675
|
-
*
|
|
1769
|
+
* Submit a signed transaction to the blockchain.
|
|
1676
1770
|
*
|
|
1677
|
-
*
|
|
1678
|
-
*
|
|
1771
|
+
* Sends the transaction to the network for processing. The transaction
|
|
1772
|
+
* must be fully signed before submission. Returns immediately with the
|
|
1773
|
+
* transaction signature - use {@link confirmTransaction} or
|
|
1774
|
+
* {@link sendAndConfirmTransaction} to wait for confirmation.
|
|
1679
1775
|
*
|
|
1680
|
-
* @param
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
/**
|
|
1684
|
-
* Set the recent blockhash for replay protection.
|
|
1776
|
+
* @param transaction - Serialized signed transaction bytes
|
|
1777
|
+
* @param options - Transaction submission options
|
|
1778
|
+
* @returns Transaction signature (base58 encoded)
|
|
1685
1779
|
*
|
|
1686
|
-
*
|
|
1687
|
-
*
|
|
1780
|
+
* @example
|
|
1781
|
+
* ```typescript
|
|
1782
|
+
* const signature = await client.sendTransaction(signedTx);
|
|
1783
|
+
* console.log(`Submitted: ${signature}`);
|
|
1688
1784
|
*
|
|
1689
|
-
*
|
|
1785
|
+
* // With options
|
|
1786
|
+
* const signature = await client.sendTransaction(signedTx, {
|
|
1787
|
+
* skipPreflight: true,
|
|
1788
|
+
* maxRetries: 3,
|
|
1789
|
+
* });
|
|
1790
|
+
* ```
|
|
1690
1791
|
*/
|
|
1691
|
-
|
|
1792
|
+
sendTransaction(transaction: Uint8Array, options?: SendTransactionOptions): Promise<string>;
|
|
1692
1793
|
/**
|
|
1693
|
-
*
|
|
1794
|
+
* Wait for a transaction to be confirmed.
|
|
1694
1795
|
*
|
|
1695
|
-
*
|
|
1696
|
-
* It
|
|
1796
|
+
* A transaction is considered confirmed when:
|
|
1797
|
+
* - It has been processed in a block (`blockHeight > 0`)
|
|
1697
1798
|
*
|
|
1698
|
-
* @param
|
|
1799
|
+
* @param signature - Transaction signature to monitor
|
|
1800
|
+
* @param options - Confirmation options
|
|
1801
|
+
* @returns Confirmed transaction details
|
|
1802
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
1803
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
1699
1804
|
*/
|
|
1700
|
-
|
|
1805
|
+
confirmTransaction(signature: string, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
|
|
1701
1806
|
/**
|
|
1702
|
-
*
|
|
1807
|
+
* Submit a signed transaction and wait for confirmation.
|
|
1703
1808
|
*
|
|
1704
|
-
*
|
|
1809
|
+
* Polls the transaction status until it is confirmed (blockHeight > 0),
|
|
1810
|
+
* or until the maximum number of retries is reached.
|
|
1811
|
+
*
|
|
1812
|
+
* @param transaction - Serialized signed transaction bytes
|
|
1813
|
+
* @param options - Transaction submission and confirmation options
|
|
1814
|
+
* @returns Confirmed transaction details
|
|
1815
|
+
* @throws {TransactionFailedError} If the transaction fails on-chain
|
|
1816
|
+
* @throws {TransactionConfirmationTimeoutError} If confirmation times out
|
|
1817
|
+
*
|
|
1818
|
+
* @example
|
|
1819
|
+
* ```typescript
|
|
1820
|
+
* const result = await client.sendAndConfirmTransaction(signedTx);
|
|
1821
|
+
* console.log(`Confirmed in block ${result.blockHeight}, executed: ${result.executed}`);
|
|
1822
|
+
*
|
|
1823
|
+
* // With custom retry settings
|
|
1824
|
+
* const result = await client.sendAndConfirmTransaction(signedTx, {
|
|
1825
|
+
* maxRetries: 3,
|
|
1826
|
+
* retryDelay: 500,
|
|
1827
|
+
* });
|
|
1828
|
+
* ```
|
|
1705
1829
|
*/
|
|
1706
|
-
|
|
1830
|
+
sendAndConfirmTransaction(transaction: Uint8Array, options?: SendAndConfirmOptions): Promise<ConfirmedTransaction>;
|
|
1707
1831
|
/**
|
|
1708
|
-
*
|
|
1832
|
+
* Request an airdrop of tokens to an account.
|
|
1709
1833
|
*
|
|
1710
|
-
*
|
|
1834
|
+
* **Note**: Only available on devnet and testnet networks.
|
|
1835
|
+
*
|
|
1836
|
+
* Returns immediately with the airdrop transaction signature.
|
|
1837
|
+
* Use {@link requestAirdropAndConfirm} to wait for the airdrop to complete.
|
|
1838
|
+
*
|
|
1839
|
+
* @param pubkey - The public key of the account to receive tokens
|
|
1840
|
+
* @param amount - Amount to airdrop in kelvins (smallest unit)
|
|
1841
|
+
* @returns Airdrop transaction signature
|
|
1842
|
+
*
|
|
1843
|
+
* @example
|
|
1844
|
+
* ```typescript
|
|
1845
|
+
* const signature = await client.requestAirdrop(publicKey, 1_000_000_000n);
|
|
1846
|
+
* console.log(`Airdrop requested: ${signature}`);
|
|
1847
|
+
* ```
|
|
1711
1848
|
*/
|
|
1712
|
-
|
|
1849
|
+
requestAirdrop(pubkey: PublicKey, amount: bigint): Promise<string>;
|
|
1713
1850
|
/**
|
|
1714
|
-
*
|
|
1851
|
+
* Request an airdrop of tokens and wait for confirmation.
|
|
1715
1852
|
*
|
|
1716
|
-
*
|
|
1853
|
+
* **Note**: Only available on devnet and testnet networks.
|
|
1717
1854
|
*
|
|
1718
|
-
* @
|
|
1719
|
-
*
|
|
1855
|
+
* Combines {@link requestAirdrop} and {@link confirmTransaction} into
|
|
1856
|
+
* a single call for convenience.
|
|
1857
|
+
*
|
|
1858
|
+
* @param pubkey - The public key of the account to receive tokens
|
|
1859
|
+
* @param amount - Amount to airdrop in kelvins (smallest unit)
|
|
1860
|
+
* @param options - Confirmation options (max retries, retry delay)
|
|
1861
|
+
* @returns Confirmed transaction details
|
|
1862
|
+
* @throws {RpcError} If the airdrop transaction fails or confirmation times out
|
|
1720
1863
|
*
|
|
1721
1864
|
* @example
|
|
1722
1865
|
* ```typescript
|
|
1723
|
-
* const
|
|
1724
|
-
*
|
|
1866
|
+
* const result = await client.requestAirdropAndConfirm(publicKey, 1_000_000_000n);
|
|
1867
|
+
* if (result.executed) {
|
|
1868
|
+
* console.log("Airdrop confirmed!");
|
|
1869
|
+
* }
|
|
1725
1870
|
* ```
|
|
1726
1871
|
*/
|
|
1727
|
-
|
|
1872
|
+
requestAirdropAndConfirm(pubkey: PublicKey, amount: bigint, options?: ConfirmTransactionOptions): Promise<ConfirmedTransaction>;
|
|
1873
|
+
private getTransaction;
|
|
1874
|
+
/**
|
|
1875
|
+
* Sleeps for a given number of milliseconds.
|
|
1876
|
+
* @param ms - The number of milliseconds to sleep.
|
|
1877
|
+
* @returns A promise that resolves when the sleep is complete.
|
|
1878
|
+
*/
|
|
1879
|
+
private sleep;
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* Error codes for RPC operations, categorized by type.
|
|
1884
|
+
*/
|
|
1885
|
+
declare enum RpcErrorCode {
|
|
1886
|
+
REQUEST_TIMEOUT = "REQUEST_TIMEOUT",
|
|
1887
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
1888
|
+
CONNECTION_REFUSED = "CONNECTION_REFUSED",
|
|
1889
|
+
INVALID_NETWORK = "INVALID_NETWORK",
|
|
1890
|
+
INVALID_RESPONSE = "INVALID_RESPONSE",
|
|
1891
|
+
PARSE_ERROR = "PARSE_ERROR",
|
|
1892
|
+
INVALID_REQUEST = "INVALID_REQUEST",
|
|
1893
|
+
METHOD_NOT_FOUND = "METHOD_NOT_FOUND",
|
|
1894
|
+
INVALID_PARAMS = "INVALID_PARAMS",
|
|
1895
|
+
INTERNAL_ERROR = "INTERNAL_ERROR",
|
|
1896
|
+
TRANSACTION_REJECTED = "TRANSACTION_REJECTED",
|
|
1897
|
+
INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS",
|
|
1898
|
+
TRANSACTION_CONFIRMATION_TIMEOUT = "TRANSACTION_CONFIRMATION_TIMEOUT",
|
|
1899
|
+
ACCOUNT_NOT_FOUND = "ACCOUNT_NOT_FOUND",
|
|
1900
|
+
RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED",
|
|
1901
|
+
NODE_UNHEALTHY = "NODE_UNHEALTHY"
|
|
1902
|
+
}
|
|
1903
|
+
/**
|
|
1904
|
+
* Detailed error context for debugging and error handling.
|
|
1905
|
+
*/
|
|
1906
|
+
interface RpcErrorDetails {
|
|
1907
|
+
method?: string;
|
|
1908
|
+
params?: unknown;
|
|
1909
|
+
requestId?: number;
|
|
1910
|
+
url?: string;
|
|
1911
|
+
httpStatus?: number;
|
|
1912
|
+
rpcCode?: number;
|
|
1913
|
+
timeout?: number;
|
|
1914
|
+
attempts?: number;
|
|
1915
|
+
[key: string]: unknown;
|
|
1916
|
+
}
|
|
1917
|
+
/**
|
|
1918
|
+
* Error class for RPC operations with structured error information.
|
|
1919
|
+
*
|
|
1920
|
+
* Provides actionable error messages and indicates whether errors are retryable.
|
|
1921
|
+
*/
|
|
1922
|
+
declare class RpcError extends Error {
|
|
1923
|
+
readonly code: RpcErrorCode;
|
|
1924
|
+
readonly details: RpcErrorDetails;
|
|
1925
|
+
readonly retryable: boolean;
|
|
1926
|
+
constructor(code: RpcErrorCode, message: string, details?: RpcErrorDetails, retryable?: boolean);
|
|
1927
|
+
static requestTimeout(timeoutMs: number, details: RpcErrorDetails): RpcError;
|
|
1928
|
+
static networkError(message: string, details: RpcErrorDetails): RpcError;
|
|
1929
|
+
static invalidResponse(details: RpcErrorDetails): RpcError;
|
|
1930
|
+
static accountNotFound(pubkey: string): RpcError;
|
|
1931
|
+
static rateLimitExceeded(details: RpcErrorDetails): RpcError;
|
|
1932
|
+
static fromRpcCode(rpcCode: number, message: string, details: RpcErrorDetails): RpcError;
|
|
1933
|
+
toJSON(): {
|
|
1934
|
+
code: RpcErrorCode;
|
|
1935
|
+
message: string;
|
|
1936
|
+
details?: Record<string, unknown>;
|
|
1937
|
+
retryable: boolean;
|
|
1938
|
+
};
|
|
1728
1939
|
}
|
|
1729
1940
|
|
|
1941
|
+
/**
|
|
1942
|
+
* Creates an RPC client with automatic retry and timeout handling.
|
|
1943
|
+
*
|
|
1944
|
+
* @param config - Client configuration with chain definition and optional transport settings
|
|
1945
|
+
* @param config.chain - Chain definition (e.g., RIALO_DEVNET_CHAIN, RIALO_MAINNET_CHAIN) or a custom chain with your own rpcUrl
|
|
1946
|
+
* @param config.transport - Optional transport configuration (timeout, retries, headers)
|
|
1947
|
+
* @returns Configured RialoClient instance
|
|
1948
|
+
*
|
|
1949
|
+
* @example
|
|
1950
|
+
* ```typescript
|
|
1951
|
+
* // Basic usage with preset chain
|
|
1952
|
+
* const client = createRialoClient({ chain: RIALO_DEVNET_CHAIN });
|
|
1953
|
+
*
|
|
1954
|
+
* // With custom transport config
|
|
1955
|
+
* const client = createRialoClient({
|
|
1956
|
+
* chain: RIALO_MAINNET_CHAIN,
|
|
1957
|
+
* transport: { timeout: 30000, maxRetries: 5 }
|
|
1958
|
+
* });
|
|
1959
|
+
*
|
|
1960
|
+
* // With custom RPC URL
|
|
1961
|
+
* const client = createRialoClient({
|
|
1962
|
+
* chain: {
|
|
1963
|
+
* id: 'rialo:mainnet',
|
|
1964
|
+
* name: 'Mainnet',
|
|
1965
|
+
* rpcUrl: 'https://mainnet.custom-rpc.com:4101'
|
|
1966
|
+
* },
|
|
1967
|
+
* });
|
|
1968
|
+
* ```
|
|
1969
|
+
*/
|
|
1970
|
+
declare function createRialoClient(config: RialoClientConfig): RialoClient;
|
|
1971
|
+
/**
|
|
1972
|
+
* Returns a default RialoClientConfig for a given network.
|
|
1973
|
+
*
|
|
1974
|
+
* Provides preset chain configurations for standard Rialo networks, making it easy
|
|
1975
|
+
* to connect to mainnet, devnet, testnet, or localnet without manual configuration.
|
|
1976
|
+
*
|
|
1977
|
+
* @param network - Network identifier: "mainnet", "devnet", "testnet", or "localnet"
|
|
1978
|
+
* @returns Default RialoClientConfig for the specified network
|
|
1979
|
+
* @throws {RpcError} With code INVALID_NETWORK if an unknown network is provided
|
|
1980
|
+
*
|
|
1981
|
+
* @example
|
|
1982
|
+
* ```typescript
|
|
1983
|
+
* // Get devnet config and create client
|
|
1984
|
+
* const config = getDefaultRialoClientConfig('devnet');
|
|
1985
|
+
* const client = createRialoClient(config);
|
|
1986
|
+
*
|
|
1987
|
+
* // Customize the config with transport options
|
|
1988
|
+
* const config = getDefaultRialoClientConfig('mainnet');
|
|
1989
|
+
* const client = createRialoClient({
|
|
1990
|
+
* ...config,
|
|
1991
|
+
* transport: { timeout: 60000, maxRetries: 5 }
|
|
1992
|
+
* });
|
|
1993
|
+
*
|
|
1994
|
+
* // Use custom RPC URL while preserving network identity
|
|
1995
|
+
* const config = getDefaultRialoClientConfig('mainnet');
|
|
1996
|
+
* const client = createRialoClient({
|
|
1997
|
+
* ...config,
|
|
1998
|
+
* chain: {
|
|
1999
|
+
* ...config.chain,
|
|
2000
|
+
* rpcUrl: 'https://mainnet.custom-rpc.com:4101'
|
|
2001
|
+
* },
|
|
2002
|
+
* });
|
|
2003
|
+
* ```
|
|
2004
|
+
*/
|
|
2005
|
+
declare function getDefaultRialoClientConfig(network: RialoNetwork): RialoClientConfig;
|
|
2006
|
+
|
|
1730
2007
|
/**
|
|
1731
2008
|
* Converts bytes to base64 string.
|
|
1732
2009
|
*
|
|
@@ -1771,4 +2048,4 @@ declare function getMainnetUrl(): string;
|
|
|
1771
2048
|
*/
|
|
1772
2049
|
declare function getLocalnetUrl(): string;
|
|
1773
2050
|
|
|
1774
|
-
export { type AccountInfo, type AccountMeta, AccountMetaTable, BASE_DERIVATION_PATH,
|
|
2051
|
+
export { type AccountInfo, type AccountMeta, AccountMetaTable, BASE_DERIVATION_PATH, BaseRpcClient, type ChainDefinition, type CompiledInstruction, type ConfirmTransactionOptions, type ConfirmedTransaction, CryptoError, CryptoErrorCode, DEFAULT_NUM_ACCOUNTS, type EpochInfoResponse, type GetConnectedFullNodesResponse, type GetFeeForMessageResponse, type GetHealthResponse, type GetSignaturesForAddressConfig, type GetSignaturesForAddressResponse, type GetSubscriptionsResponse, type GetTransactionsConfig, type GetTransactionsResponse, type GetTriggeredTransactionsResponse, type GetValidatorHealthResponse, type GetWorkflowLineageRequest, type GetWorkflowLineageResponse, HttpTransport, type HttpTransportConfig, type IdentifierString, type Instruction, type IsBlockhashValidResponse, KELVIN_PER_RLO, Keypair, KeypairSigner, Message, type MessageHeader, Mnemonic, type MnemonicStrength, type MultipleAccountsResponse, PUBLIC_KEY_LENGTH, PublicKey, QueryRpcClient, RIALO_DEVNET_CHAIN, RIALO_LOCALNET_CHAIN, RIALO_MAINNET_CHAIN, RIALO_TESTNET_CHAIN, RialoClient, type RialoClientConfig, RialoError, RialoErrorType, type RialoNetwork, RpcError, RpcErrorCode, type RpcErrorDetails$1 as RpcErrorDetails, SECRET_KEY_LENGTH, SIGNATURE_LENGTH, SYSTEM_PROGRAM_ID, type SendAndConfirmOptions, type SendTransactionOptions, Signature, type SignatureStatus, type Signer, SystemInstruction, Transaction, TransactionBuilder, TransactionError, TransactionErrorCode, type TransactionResponse, TransactionRpcClient, URL_DEVNET, URL_LOCALNET, URL_MAINNET, URL_TESTNET, calculateBackoff, createAccount, createBorshInstruction, createRialoClient, encodeBorshData, fromBase64, getDefaultRialoClientConfig, getDevnetUrl, getLocalnetUrl, getMainnetUrl, getTestnetUrl, sleep, toBase64, transferInstruction };
|