Closed Magofoco closed 1 year ago
hey, this is because currently the mainnet and goerli ENS subgraphs differ slightly, meaning that sometimes things will break on mainnet for the moment. a fix for this issue at the moment could be to disable subgraph communication entirely by passing a null
value for graphURI
in the ENS class constructor.
e.g.
const ENSInstance = new ENS({ graphURI: null })
I tried this solution but the error persists
For now, I am solving it with a try
and catch
.
I created a standalone function called getMaybeOwner
that calls .getOwner()
. If the ens name exists, the function returns either an object or null (as expected). Else, it enters the catch
block and returns null
const getMaybeOwner = async (ensName: string, ENSInstance: ENS) => {
try {
const maybeEnsRegisteredObject = await ENSInstance.getOwner(
ensName
);
return maybeEnsRegisteredObject;
} catch (e) {
return null;
}
};
export default getMaybeOwner;
Now, instead of calling await ENSInstance.getOwner(ensName)
I call await getMaybeOwner(ensName, ENSInstance);
@TateB Do you think it is worth it to add this function in the methods of the ENSInstance
or adding it as a function into the library?
@TateB If you want, I can implement the getMaybeOwner
function
a new subgraph is syncing now, will take a few days but once it's done this should work
@Magofoco hey, this should work now
@TateB Hello!
I tried it with a ens domain that does not exist and returns correctly undefined
. HOWEVER, it returns undefined
also for a ens domain that exists (ex. vitalik.eth)
I am using: "@ensdomains/ensjs": "^3.0.0-alpha.42"
@Magofoco there were some issues with running the package through nodejs, should be fixed now (version 3.0.0-alpha.43
)
@TateB I am experiencing the same error. It returns undefined also for a ens domain that exists (ex. vitalik.eth)
can you provide a gist of your code or something? i can't replicate the issue
@TateB Sure! Here it is
import { ethers } from "ethers";
import * as dotenv from "dotenv";
import { ENS } from "@ensdomains/ensjs";
dotenv.config();
const { INFURA_API_KEY } = process.env;
const INFURA_NODE_MAINNET = `https://mainnet.infura.io/v3/${INFURA_API_KEY}`;
const provider = new ethers.providers.JsonRpcProvider(INFURA_NODE_MAINNET);
const ENSInstance = new ENS();
const POLLING_INTERVAL_MILLISECONDS = 20000;
const main = async () => {
await ENSInstance.setProvider(provider);
const polledFunction = async () => {
const existingEns = await ENSInstance.getOwner("vitalik.eth");
const nonExistingEns = await ENSInstance.getOwner("thisisnotregisteredens.eth");
console.log(existingEns); <--- RETURNS WRONGLY UNDEFINED
console.log(nonExistingEns); <-- RETURNS UNDEFINED
};
setInterval(polledFunction, POLLING_INTERVAL_MILLISECONDS);
};
main()
still can't replicate the issue, do you think you could create a barebones repo for reproducing it?
@TateB Take a look here: https://github.com/Magofoco/ensIssueTest
a few minor things that got it working for me:
package.json
: add "type": "module"
tsconfig.json
:
module
to ESNext
moduleResolution
to node
Thanks @TateB , with your changes the version 3.0.0-alpha.43
work as expected.
Thank you!
(Just for your knowledge, 3.0.0-alpha.39
was working without needing to change the package.json
and tsconfig.json
)
On Mainnet, the function
.getOwner
crashes with an error if the ENS domain name input to the function has not been registered.Example:
crashes with the following error instead of returning
undefined
However On Goerli Network, the same function does not crash and returns, correctly,
undefined
since the ens domain "thisisnotregisteredens.eth" is still available to be purchased