Skip to content

Commit

Permalink
Better errors when non-string address or ENS name is passed into Cont…
Browse files Browse the repository at this point in the history
…racts or provider methods (#1051).
  • Loading branch information
ricmoo committed Oct 16, 2021
1 parent 8947fd4 commit a5c6a46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/contracts/src.ts/index.ts
Expand Up @@ -116,6 +116,10 @@ const allowedTransactionKeys: { [ key: string ]: boolean } = {
async function resolveName(resolver: Signer | Provider, nameOrPromise: string | Promise<string>): Promise<string> {
const name = await nameOrPromise;

if (typeof(name) !== "string") {
logger.throwArgumentError("invalid address or ENS name", "name", name);
}

// If it is already an address, just use it (after adding checksum)
try {
return getAddress(name);
Expand Down
5 changes: 5 additions & 0 deletions packages/providers/src.ts/base-provider.ts
Expand Up @@ -1313,6 +1313,11 @@ export class BaseProvider extends Provider implements EnsProvider {
}

async _getAddress(addressOrName: string | Promise<string>): Promise<string> {
addressOrName = await addressOrName;
if (typeof(addressOrName) !== "string") {
logger.throwArgumentError("invalid address or ENS name", "name", addressOrName);
}

const address = await this.resolveName(addressOrName);
if (address == null) {
logger.throwError("ENS name not configured", Logger.errors.UNSUPPORTED_OPERATION, {
Expand Down

0 comments on commit a5c6a46

Please sign in to comment.