Skip to content

Commit

Permalink
feat(Provider): add Provider.getProtocolVersion() method
Browse files Browse the repository at this point in the history
  • Loading branch information
danijelTxFusion committed Jun 19, 2024
1 parent 034011f commit daa3670
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
RawBlockTransaction,
StorageProof,
PaymasterParams,
Eip712Meta, LogProof, Token,
Eip712Meta, LogProof, Token, ProtocolVersion,
} from './types';
import {
BOOTLOADER_FORMAL_ADDRESS,
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
*
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit daa3670

Please sign in to comment.