@openzeppelin/ui-builder-adapter-evm 0.16.0 → 1.0.0

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/dist/index.d.cts CHANGED
@@ -207,6 +207,10 @@ declare class EvmAdapter implements ContractAdapter {
207
207
  * @inheritdoc
208
208
  */
209
209
  getExplorerTxUrl?(txHash: string): string | null;
210
+ /**
211
+ * @inheritdoc
212
+ */
213
+ getCurrentBlock(): Promise<number>;
210
214
  /**
211
215
  * @inheritdoc
212
216
  */
package/dist/index.d.ts CHANGED
@@ -207,6 +207,10 @@ declare class EvmAdapter implements ContractAdapter {
207
207
  * @inheritdoc
208
208
  */
209
209
  getExplorerTxUrl?(txHash: string): string | null;
210
+ /**
211
+ * @inheritdoc
212
+ */
213
+ getCurrentBlock(): Promise<number>;
210
214
  /**
211
215
  * @inheritdoc
212
216
  */
package/dist/index.js CHANGED
@@ -1022,6 +1022,41 @@ async function testEvmRpcConnection(rpcConfig, timeoutMs = 5e3) {
1022
1022
  clearTimeout(timeoutId);
1023
1023
  }
1024
1024
  }
1025
+ async function getEvmCurrentBlock(networkConfig) {
1026
+ const rpcUrl = resolveRpcUrl(networkConfig);
1027
+ try {
1028
+ const response = await fetch(rpcUrl, {
1029
+ method: "POST",
1030
+ headers: { "Content-Type": "application/json" },
1031
+ body: JSON.stringify({
1032
+ jsonrpc: "2.0",
1033
+ method: "eth_blockNumber",
1034
+ params: [],
1035
+ id: 1
1036
+ })
1037
+ });
1038
+ if (!response.ok) {
1039
+ throw new Error(`RPC request failed with status ${response.status}`);
1040
+ }
1041
+ const data = await response.json();
1042
+ if (data.error) {
1043
+ throw new Error(data.error.message || "RPC error");
1044
+ }
1045
+ if (data.result === void 0 || data.result === null) {
1046
+ throw new Error("RPC response missing result field");
1047
+ }
1048
+ const blockNumber = parseInt(data.result, 16);
1049
+ if (isNaN(blockNumber)) {
1050
+ throw new Error(`Invalid block number returned: ${data.result}`);
1051
+ }
1052
+ return blockNumber;
1053
+ } catch (error) {
1054
+ logger5.error("getEvmCurrentBlock", "Failed to get current block:", error);
1055
+ throw new Error(
1056
+ `Failed to get current block: ${error instanceof Error ? error.message : String(error)}`
1057
+ );
1058
+ }
1059
+ }
1025
1060
 
1026
1061
  // src/configuration/network-services.ts
1027
1062
  function getEvmNetworkServiceForms(networkConfig) {
@@ -5912,6 +5947,12 @@ var EvmAdapter = class {
5912
5947
  }
5913
5948
  return null;
5914
5949
  }
5950
+ /**
5951
+ * @inheritdoc
5952
+ */
5953
+ async getCurrentBlock() {
5954
+ return getEvmCurrentBlock(this.networkConfig);
5955
+ }
5915
5956
  /**
5916
5957
  * @inheritdoc
5917
5958
  */