diff --git a/web3.js/module.d.ts b/web3.js/module.d.ts index e0a95c087e..da837401b5 100644 --- a/web3.js/module.d.ts +++ b/web3.js/module.d.ts @@ -285,6 +285,9 @@ declare module '@solana/web3.js' { authorizedPubkey: PublicKey; nonce: Blockhash; feeCalculator: FeeCalculator; + static fromAccountData( + buffer: Buffer | Uint8Array | Array, + ): NonceAccount; } export const NONCE_ACCOUNT_LENGTH: number; diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index a9af3d5d96..8a894a8320 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -298,6 +298,9 @@ declare module '@solana/web3.js' { authorizedPubkey: PublicKey; nonce: Blockhash; feeCalculator: FeeCalculator; + static fromAccountData( + buffer: Buffer | Uint8Array | Array, + ): NonceAccount; } declare export var NONCE_ACCOUNT_LENGTH: number; diff --git a/web3.js/src/nonce-account.js b/web3.js/src/nonce-account.js index 1d02cc86ad..99d0d6e750 100644 --- a/web3.js/src/nonce-account.js +++ b/web3.js/src/nonce-account.js @@ -6,6 +6,7 @@ import * as Layout from './layout'; import {PublicKey} from './publickey'; import type {FeeCalculator} from './fee-calculator'; import {FeeCalculatorLayout} from './fee-calculator'; +import {toBuffer} from './util/to-buffer'; /** * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32 @@ -36,8 +37,10 @@ export class NonceAccount { * @param buffer account data * @return NonceAccount */ - static fromAccountData(buffer: Buffer): NonceAccount { - const nonceAccount = NonceAccountLayout.decode(buffer, 0); + static fromAccountData( + buffer: Buffer | Uint8Array | Array, + ): NonceAccount { + const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0); nonceAccount.authorizedPubkey = new PublicKey( nonceAccount.authorizedPubkey, );