diff --git a/src/provider.ts b/src/provider.ts index 0cde55d..0212a7d 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -35,7 +35,7 @@ import { RawBlockTransaction, StorageProof, PaymasterParams, - Eip712Meta, LogProof, Token, + Eip712Meta, LogProof, Token, ProtocolVersion, } from './types'; import { BOOTLOADER_FORMAL_ADDRESS, @@ -670,6 +670,24 @@ export class Provider extends ethers.providers.JsonRpcProvider { } } + /** + * Return the protocol version + * + * Calls the {@link https://docs.zksync.io/build/api.html#zks_getprotocolversion zks_getProtocolVersion} JSON-RPC method. + * + * @param [id] Specific version ID. + * + * @example + * + * import { Provider, types } from "zksync-ethers"; + * + * const provider = Provider.getDefaultProvider(types.Network.Sepolia); + * console.log(`Protocol version: ${await provider.getProtocolVersion()}`); + */ + async getProtocolVersion(id?: number): Promise<ProtocolVersion> { + return await this.send('zks_getProtocolVersion', [id]); + } + /** * Returns an estimate of the amount of gas required to submit a transaction from L1 to L2. * @@ -2205,6 +2223,20 @@ export class Web3Provider extends Provider { return super.l1TokenAddress(token); } + /** + * @inheritDoc + * + * @example + * + * import { Web3Provider } from "zksync-ethers"; + * + * const provider = new Web3Provider(window.ethereum); + * console.log(`Protocol version: ${await provider.getProtocolVersion()}`); + */ + override async getProtocolVersion(id?: number): Promise<ProtocolVersion> { + return super.getProtocolVersion(id); + } + /** * @inheritDoc * diff --git a/tests/integration/provider.test.ts b/tests/integration/provider.test.ts index 792cd95..e70948a 100644 --- a/tests/integration/provider.test.ts +++ b/tests/integration/provider.test.ts @@ -90,6 +90,13 @@ describe('Provider', () => { }); }); + describe('#getProtocolVersion()', () => { + it('should return the latest protocol version', async () => { + const result = await provider.getProtocolVersion(); + expect(result).not.to.be.null; + }); + }); + describe('#getMainContractAddress()', () => { it('should return the address of main contract', async () => { const result = await provider.getMainContractAddress();