Skip to content

Commit 653922f

Browse files
committed
feat(lib): utils.isValidEvmAddress(string)
1 parent c33ac6f commit 653922f

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/bin/cli/networks.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = async (flags = {}, [ecosystem]) => {
3838
]),
3939
),
4040
);
41-
41+
4242
if (networks.length > 0) {
4343
helpers.traceTable(
4444
networks.map((network) => [

src/lib/utils.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { Witnet } from "@witnet/sdk";
22

33
import { default as cbor } from "cbor";
44

5-
import { AbiCoder, Contract, type JsonRpcApiProvider, type JsonRpcProvider, solidityPackedKeccak256 } from "ethers";
5+
import {
6+
AbiCoder,
7+
Contract,
8+
isAddress,
9+
type JsonRpcApiProvider,
10+
type JsonRpcProvider,
11+
solidityPackedKeccak256,
12+
} from "ethers";
613
import { default as merge } from "lodash.merge";
714
import { default as helpers } from "../bin/helpers.cjs";
815
import { ABIs } from "../index.js";
@@ -234,6 +241,15 @@ export function isEvmNetworkSupported(network: string): boolean {
234241
return helpers.supportsNetwork(network);
235242
}
236243

244+
export function isValidEvmAddress(address?: string): boolean {
245+
return (
246+
address !== undefined &&
247+
address !== "0x0000000000000000000000000000000000000000" &&
248+
/^0x[0-9a-fA-F]{40}$/.test(address) &&
249+
isAddress(address)
250+
);
251+
}
252+
237253
export function abiDecodeQueryStatus(status: bigint): WitOracleQueryStatus {
238254
switch (status) {
239255
case 1n:

0 commit comments

Comments
 (0)