@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.cjs CHANGED
@@ -1072,6 +1072,41 @@ async function testEvmRpcConnection(rpcConfig, timeoutMs = 5e3) {
1072
1072
  clearTimeout(timeoutId);
1073
1073
  }
1074
1074
  }
1075
+ async function getEvmCurrentBlock(networkConfig) {
1076
+ const rpcUrl = resolveRpcUrl(networkConfig);
1077
+ try {
1078
+ const response = await fetch(rpcUrl, {
1079
+ method: "POST",
1080
+ headers: { "Content-Type": "application/json" },
1081
+ body: JSON.stringify({
1082
+ jsonrpc: "2.0",
1083
+ method: "eth_blockNumber",
1084
+ params: [],
1085
+ id: 1
1086
+ })
1087
+ });
1088
+ if (!response.ok) {
1089
+ throw new Error(`RPC request failed with status ${response.status}`);
1090
+ }
1091
+ const data = await response.json();
1092
+ if (data.error) {
1093
+ throw new Error(data.error.message || "RPC error");
1094
+ }
1095
+ if (data.result === void 0 || data.result === null) {
1096
+ throw new Error("RPC response missing result field");
1097
+ }
1098
+ const blockNumber = parseInt(data.result, 16);
1099
+ if (isNaN(blockNumber)) {
1100
+ throw new Error(`Invalid block number returned: ${data.result}`);
1101
+ }
1102
+ return blockNumber;
1103
+ } catch (error) {
1104
+ import_ui_builder_utils5.logger.error("getEvmCurrentBlock", "Failed to get current block:", error);
1105
+ throw new Error(
1106
+ `Failed to get current block: ${error instanceof Error ? error.message : String(error)}`
1107
+ );
1108
+ }
1109
+ }
1075
1110
 
1076
1111
  // src/configuration/network-services.ts
1077
1112
  function getEvmNetworkServiceForms(networkConfig) {
@@ -5851,6 +5886,12 @@ var EvmAdapter = class {
5851
5886
  }
5852
5887
  return null;
5853
5888
  }
5889
+ /**
5890
+ * @inheritdoc
5891
+ */
5892
+ async getCurrentBlock() {
5893
+ return getEvmCurrentBlock(this.networkConfig);
5894
+ }
5854
5895
  /**
5855
5896
  * @inheritdoc
5856
5897
  */