View Categories

Integrate using NPM Package

Integrating ODude Name Using the NPM Package

ODude Name simplifies Web3 domain resolution by linking human-readable names to wallet addresses, websites, and metadata. This tutorial will guide you through integrating ODude Name into your project using the @odude/oduderesolve NPM package.

Prerequisites

Before you start, 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)

Step 1: Install the Package

To get started, install the @odude/oduderesolve package using npm or yarn:

npm install @odude/oduderesolve

or

yarn add @odude/oduderesolve

Step 2: Configure the Resolver

Create a configuration object with blockchain RPC URLs and a wallet private key:

const settings = {
  matic_rpc_url: "https://polygon-mainnet.g.alchemy.com/v2/your-api-key",  // Replace with your RPC URL
  eth_rpc_url: "https://eth-mainnet.g.alchemy.com/v2/your-api-key",       // Replace with your RPC URL
  fvm_rpc_url: "https://api.node.glif.io/rpc/v1",
  wallet_pvt_key: "your-empty-wallet-private-key" // Replace with your private key
};

Step 3: Initialize the Resolver

Import and instantiate the ODude Name resolver:

const ODudeName = require("@odude/oduderesolve");
const resolve = new ODudeName(settings);

Step 4: Resolve ODude Names

Get Wallet Address from ODude Name

resolve.getAddress("hello@web3", "ETH").then(address => {
  console.log("Wallet address of hello@web3 is: ", address);
}).catch(console.error);

Get ODude Name from Wallet Address

resolve.getDomain("0xaa481F8d2d966e5fCC0446fA459F5d580AE5ea9f", "MATIC").then(name => {
  console.log("ODude Name associated with wallet: ", name);
}).catch(console.error);

Get TokenURI from ODude Name

resolve.w3d_tokenURI("hello@web3").then(tokenURI => {
  console.log("TokenURI of hello@web3 is: ", tokenURI);
}).catch(console.error);

Get Website URL from ODude Name

resolve.getWeb("hello@web3").then(url => {
  console.log("Website URL of hello@web3 is: ", url);
}).catch(console.error);

Step 5: Running the Integration

Create a file (e.g., index.js) and add the above code. Then, execute it with:

node index.js

If the setup is correct, you should see the corresponding wallet address, ODude Name, TokenURI, or website URL in the console.

Conclusion

By integrating ODude Name using @odude/oduderesolve, you can enhance your Web3 applications with seamless domain resolution. This allows users to interact with wallet addresses and decentralized websites in a human-readable way.

For more advanced use cases, refer to the ODude Name GitHub repository.

Happy coding! 🚀