diff --git a/web3.js/src/connection.ts b/web3.js/src/connection.ts index cd8f0a6c53..18ac600845 100644 --- a/web3.js/src/connection.ts +++ b/web3.js/src/connection.ts @@ -1711,6 +1711,16 @@ export type GetParsedProgramAccountsConfig = { filters?: GetProgramAccountsFilter[]; }; +/** + * Configuration object for getMultipleAccounts + */ +export type GetMultipleAccountsConfig = { + /** Optional commitment level */ + commitment?: Commitment; + /** Optional encoding for account data (default base64) */ + encoding?: 'base64' | 'jsonParsed'; +}; + /** * Information describing an account */ @@ -2479,14 +2489,27 @@ export class Connection { */ async getMultipleAccountsInfo( publicKeys: PublicKey[], - commitment?: Commitment, - ): Promise<(AccountInfo | null)[]> { + configOrCommitment?: GetMultipleAccountsConfig | Commitment, + ): Promise<(AccountInfo | null)[]> { const keys = publicKeys.map(key => key.toBase58()); - const args = this._buildArgs([keys], commitment, 'base64'); + + let commitment; + let encoding: 'base64' | 'jsonParsed' = 'base64'; + if (configOrCommitment) { + if (typeof configOrCommitment === 'string') { + commitment = configOrCommitment; + encoding = 'base64'; + } else { + commitment = configOrCommitment.commitment; + encoding = configOrCommitment.encoding || 'base64'; + } + } + + const args = this._buildArgs([keys], commitment, encoding); const unsafeRes = await this._rpcRequest('getMultipleAccounts', args); const res = create( unsafeRes, - jsonRpcResultAndContext(array(nullable(AccountInfoResult))), + jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))), ); if ('error' in res) { throw new Error(