diff --git a/packages/providers/src.ts/base-provider.ts b/packages/providers/src.ts/base-provider.ts index df833b83c..1f3416d95 100644 --- a/packages/providers/src.ts/base-provider.ts +++ b/packages/providers/src.ts/base-provider.ts @@ -452,7 +452,7 @@ export class BaseProvider extends Provider { getBalance(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise { return this._runPerform("getBalance", { - address: () => this.resolveName(addressOrName), + address: () => this._getAddress(addressOrName), blockTag: () => this._getBlockTag(blockTag) }).then((result) => { return BigNumber.from(result); @@ -461,7 +461,7 @@ export class BaseProvider extends Provider { getTransactionCount(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise { return this._runPerform("getTransactionCount", { - address: () => this.resolveName(addressOrName), + address: () => this._getAddress(addressOrName), blockTag: () => this._getBlockTag(blockTag) }).then((result) => { return BigNumber.from(result).toNumber(); @@ -470,7 +470,7 @@ export class BaseProvider extends Provider { getCode(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise { return this._runPerform("getCode", { - address: () => this.resolveName(addressOrName), + address: () => this._getAddress(addressOrName), blockTag: () => this._getBlockTag(blockTag) }).then((result) => { return hexlify(result); @@ -479,7 +479,7 @@ export class BaseProvider extends Provider { getStorageAt(addressOrName: string | Promise, position: BigNumberish | Promise, blockTag?: BlockTag | Promise): Promise { return this._runPerform("getStorageAt", { - address: () => this.resolveName(addressOrName), + address: () => this._getAddress(addressOrName), blockTag: () => this._getBlockTag(blockTag), position: () => Promise.resolve(position).then((p) => hexValue(p)) }).then((result) => { @@ -546,7 +546,7 @@ export class BaseProvider extends Provider { let tx: any = { }; ["from", "to"].forEach((key) => { if (t[key] == null) { return; } - tx[key] = Promise.resolve(t[key]).then(a => (a ? this.resolveName(a): null)) + tx[key] = Promise.resolve(t[key]).then(a => (a ? this._getAddress(a): null)) }); ["data", "gasLimit", "gasPrice", "value"].forEach((key) => { if (t[key] == null) { return; } @@ -561,7 +561,7 @@ export class BaseProvider extends Provider { let filter: any = { }; if (f.address != null) { - filter.address = this.resolveName(f.address); + filter.address = this._getAddress(f.address); } if (f.topics) { @@ -599,6 +599,17 @@ export class BaseProvider extends Provider { }); } + _getAddress(addressOrName: string | Promise): Promise { + return this.resolveName(addressOrName).then((address) => { + if (address == null) { + errors.throwError("ENS name not configured", errors.UNSUPPORTED_OPERATION, { + operation: `resolveName(${ JSON.stringify(addressOrName) })` + }); + } + return address; + }); + } + _getBlock(blockHashOrBlockTag: BlockTag | string | Promise, includeTransactions?: boolean): Promise { return this.ready.then(() => { return this._getBlockTag(blockHashOrBlockTag).then((blockHashOrBlockTag) => {