Lookup IPFS Website Using ODude Name
Interacting with decentralized websites hosted on IPFS is made easy with the @odude/oduderesolve
package. This tutorial will guide you through the process of retrieving IPFS-based website URLs using ODude Name.
Prerequisites
Before proceeding, ensure you have the following:
- Node.js installed (v14 or later recommended)
- NPM or Yarn installed
- A blockchain RPC provider (e.g., Alchemy, Infura, or QuickNode)
- Environment variables configured (optional but recommended)
Step 1: Install the Required Package
To get started, install @odude/oduderesolve
using npm or yarn:
npm install @odude/oduderesolve
or
yarn add @odude/oduderesolve
Step 2: Set Up Configuration
To interact with ODude Name, you need to provide blockchain RPC URLs and a wallet private key. This can be done via environment variables or directly in the code.
require('dotenv').config(); // Remove this line if no environment variables are used
const ODudeName = require("@odude/oduderesolve");
const settings = {
matic_rpc_url: process.env.MATIC_RPC,
eth_rpc_url: process.env.ETH_RPC,
fvm_rpc_url: process.env.FVM_RPC,
wallet_pvt_key: process.env.PVT_KEY
};
const resolve = new ODudeName(settings);
Step 3: Retrieve Website URL from ODude Name
You can fetch the IPFS-based website URL associated with an ODude Name using getWeb()
.
resolve.getWeb("hello@web3").then(url => {
console.log("hello@web3 website URL is: ", url);
}).catch(console.error);
Example Output:
hello@web3 website URL is: https://gateway.ipfs.io/ipfs/bafkreidcqmcrgmfj6fiplf73mxdqid7rmndqtsyfii72dssdhlie3vwqzq
Another Example:
resolve.getWeb("hello@fil").then(url => {
console.log("hello@fil website URL is: ", url);
}).catch(console.error);
Step 4: Retrieve TokenURI for Web3Domain Name
To get the metadata or details about a Web3 domain, use w3d_tokenURI()
.
resolve.w3d_tokenURI("hello@web3").then(uri => {
console.log("hello@web3 TokenURI: ", uri);
}).catch(console.error);
Example Output:
hello@web3 TokenURI: https://web3yak.com/temp/niki.fil.json
Another Example:
resolve.w3d_tokenURI("hello@fil").then(uri => {
console.log("hello@fil TokenURI: ", uri);
}).catch(console.error);
Step 5: Running the Script
Save the script in a file (e.g., lookup.js
) and run it with:
node lookup.js
Conclusion
By using ODude Name, you can seamlessly resolve Web3 domains into IPFS-hosted websites and metadata. This simplifies decentralized web access and enhances blockchain-based interactions.
For more advanced use cases, visit the ODude Name GitHub repository.
Happy coding! 🚀