LogoLogo
Decentraweb.orgVisit App
  • 👋Info
    • Introduction
    • Official Links
    • Decentraweb Deployments
  • ⚒️For Developers
    • Our SDKs
      • ❓About our SDKs
      • 📝Namekit
      • 🚀Core - Full Integration
    • 🦊MetaMask Unity SDK with Decentraweb
  • ❓Learn
    • About Decentraweb Domains
      • Decentraweb Domains FAQs
      • Ethereum vs Polygon Domains
      • Top-Level Web3 Domains
      • Web3 Domains
      • Web3 Subdomains
    • Using Decentraweb Domains
      • 🌉Using Domains Bridge
      • Crypto Wallet Domains
      • Resolving Decentralized Domains in your Browser
      • Setting DNS Records
      • dwebs.to Web2 Bridge
      • Using IPFS
    • Purchasing Domains
      • Web3 Domains
      • Top-Level Web3 Domains
    • Web3 TLD Guides
      • 🎨Custom Art for Domains
      • 🔁Renewing Web3 TLDs
      • 🤝Staking Web3 TLDs
      • 🤫Private Staking Web3 TLDs - Allowlist
      • ✏️Customizing Web3 Domain Registration Page
      • 💾Reserve Web3 Domains from your Web3 TLD
      • 💎Register Web3 Domains from your Web3 TLD
      • 🛒Web3 Domain Registrar Sites
      • 🖥️Web3 Domain Registration Widgets
  • 🪙DWEB
    • ❓About DWEB Token
    • 🛒Purchasing DWEB
    • ⛏️Staking DWEB
Powered by GitBook
On this page
  • Installation
  • Initialization
  • Browser Bundle (CDN Option)
  • Allowing others to Register Web3 Domains from your Web3 TLD
  • Reading & Writing Decentraweb Domain Records
  • Reading & Setting DNS Records
  • Reading & Setting Content Hash
  • Reading & Setting Text Records

Was this helpful?

  1. For Developers
  2. Our SDKs

Core - Full Integration

Learn how to integrate our full core library for interacting with our Smart Contracts

PreviousNamekitNextMetaMask Unity SDK with Decentraweb

Last updated 1 year ago

Was this helpful?

Our Core Library allows developers to integrate fully with Decentraweb and interact with our Smart Contracts, providing tools for :

  • Reading and Setting Decentraweb Domain Records

  • Reading and Setting DNS & Text Records for Decentraweb Domains

  • Registering Web3 Domains (absolutely.anything) and Web3 Subdomains (wow.absolutely.anything)

Our Core Library is perfect for developers looking to provide or sell Web3 Domain registrations, as well as allowing management of Web3 Domains all within their own platform, Website or dApp

Our Core Library contains Decentraweb's latest ABIs and can be used directly or embedded in other projects such as the Decentraweb Resolver and CLI.


View our NPM Package :

View our Advanced Docs :


Installation

To install Decentraweb Core Library, run the following within your terminal to your project directory

npm install --save @decentraweb/core ethers@5

Initialization

Initialize Decentraweb instance to read/write domain records :

import {providers, Wallet} from "ethers";
import {DWEBRegistry} from "@decentraweb/core";

const ETH_NETWORK = 'goerli';
const JSONRPC_URL = '';
const PRIVATE_KEY = '';

const provider = new providers.JsonRpcProvider(JSONRPC_URL, ETH_NETWORK);
//Signer only required if you want to write data to blockchain
const signer = new Wallet(PRIVATE_KEY, provider); 
const contracts = {
  "DWEBRegistry": "0x8eb93AB94A6Afa8d416aB1884Ebb5A3f00920a7A",
  "DefaultReverseResolver": "0x7d770Cfe9608Ff3AA3F5A34bdCd27c3870a370Da",
  "PublicResolver": "0xf157D3559DF1F8c69cb757A1A2cdF8736618E083",
  "ReverseRegistrar": "0x3D8f878584199e47a2d40A1E269042E10aa50754"
}
const dweb = new DWEBRegistry({network: ETH_NETWORK, provider, signer, contracts});

Parameters:

  1. network (required) - Ethereum network name (mainnet, goerli, matic, maticmum)

  2. contracts (optional) - used to override default Decentraweb contract addresses. Only needs to be used for development purposes.


Browser Bundle (CDN Option)

In most cases importing library using npm is preferred way, but for fast prototyping you can load it from our CDN :

<script src="https://cdn.ethers.io/lib/ethers-5.7.umd.min.js" type="application/javascript"></script>
<script src="https://cdn.decentraweb.org/decentraweb-core-2.0.0.min.js" type="application/javascript"></script>
<script>
  window.addEventListener('load', () => {
    const {DWEBRegistry} = Decentraweb;
    const dweb = new DWEBRegistry({network: 'goerli', provider: ethers.getDefaultProvider('goerli')});
    const name = dweb.name('some_dweb_name');
  })
</script>

Allowing others to Register Web3 Domains from your Web3 TLD

To initialize allowing Web3 Domain Registrations from your TLD within your dApp :

import {ethers, providers, Wallet} from "ethers";
import {sld} from "@decentraweb/core";

const ETH_NETWORK = 'mainnet';
const JSONRPC_URL = 'https://mainnet.infura.io/v3/00000000000000000000000000000000';
const PRIVATE_KEY = '0000000000000000000000000000000000000000000000000000000000000000';

const provider = new providers.JsonRpcProvider(JSONRPC_URL, ETH_NETWORK);
const signer = new Wallet(PRIVATE_KEY, provider);
const registrar = new sld.EthereumSLDRegistrar({network: ETH_NETWORK, provider, signer});
async function registerSuddomains() {
  const approvedRegistration = await registrar.approveOndemandRegistration([
    {name: 'cooldomain', label: 'hello'},
    {name: 'anything', label: 'absolutely'}
  ]);
  //It is recommended to cache approvedRegistration object, so you can resume registration if next step fails
  const tx = await registrar.registerSubdomains(approvedRegistration);
  const receipt = await tx.wait(1);
  console.log('Registered, TX hash', receipt.transactionHash);
}

registerSuddomains().then(() => {
  console.log('Done');
}).catch(err => {
  console.error(err);
});

Reading & Writing Decentraweb Domain Records

Domain names support following types of records:

  1. Wallet Addresses

  2. Content hash

  3. Text records

  4. DNS records

Domains on the Ethereum network supports all types of records, while domains on the Polygon network support only Wallet Addresses at this moment.

Writing Data to the Blockchain

A valid signer instance must be provided to enable writing data to blockchain.

Address Resolution

Get Wallet Address

const name = dweb.name('test');
const addr = await name.getAddress('ETH');

Set Wallet Address

const name = dweb.name('test');
const tx = await name.setAddress('ETH', '0x13BCb838DAEFF08f4E56237098dB1d814eeB837D');
//Optionally wait until first transaction confirmation
await tx.wait(1);

Reverse Resolution

Reverse address resolution is only possible for Ethereum wallets.

To allow reverse resolution for Wallet Address -> Decentraweb Domain :

const tx = await dweb.setReverseRecord('wow.greatdomain');
//Optionally wait until first transaction confirmation
await tx.wait(1);

This will set name "wow.greatdomain" for the wallet address that was used to sign the transaction.

To resolve Ethereum address to name use following method:

const name = await dweb.getReverseRecord('0x71C7656EC7ab88b098defB751B7401B5f6d8976F');

By default getReverseRecord also performing forward check. This mean that after finding name by address, it will also check that found name is owned by given address. To resolve address without this check, pass true as second argument:

const name = await dweb.getReverseRecord('0x71C7656EC7ab88b098defB751B7401B5f6d8976F', true);

Reading & Setting DNS Records

Reading DNS Records

import {DWEBRegistry, RecordSet} from "@decentraweb/core";

const name = dweb.name('test');
const data = await name.getDNS(RecordSet.recordType.toType('A'));
const aRecords = RecordSet.decode(data);

Setting DNS Records

import {DWEBRegistry, RecordSet} from "@decentraweb/core";

const name = dweb.name('test');
const data = RecordSet.encode([
  {
    type: 'A',
    name: 'test',
    ttl: 3600,
    class: 'IN',
    data: '192.168.0.1'
  },
  {
    type: "TXT",
    name: 'test',
    ttl: 3600,
    class: 'IN',
    data: 'this is TXT value'
  }
]);
const tx = await name.setDNS(data);
//Optionally wait until first transaction confirmation
await tx.wait(1);

Reading & Setting Content Hash

 (ipfs|ipns|bzz|onion|onion3)://{hash}
    /(ipfs|ipns)/{hash}

Reading Content URL

const name = dweb.name('test');
const contentURL = await name.getContenthash();

Setting Content URL

const name = dweb.name('test');
const tx = await name.setContenthash('ipfs://bafybeiaysi4s6lnjev27ln5icwm6tueaw2vdykrtjkwiphwekaywqhcjze');
//Optionally wait until first transaction confirmation
await tx.wait(1);

Reading & Setting Text Records

Text records allow domain owner to store simple key-value string data in domain. To remove text record simply set it to empty string.

Reading Text Records

const name = dweb.name('test');
const email = await name.getText('email');

Setting Text Records

const name = dweb.name('test');
const tx = await name.setText('email', 'foo@acme.com');
//Optionally wait until first transaction confirmation
await tx.wait(1);

This concludes our guide on installing our Core Library. If you should have any questions or need assistance, please reach out to our integrations team - integrations@decentraweb.org

provider (required) - instance to read blockchain data.

signer (optional) - instance. Only required if you want to write data to blockchain.

This library is using to interact with Ethereum blockchain. ethers.js is included as peer dependency, so don't forget to add it to your package.json

Decentraweb Web3 Domains can be registered on Ethereum or Polygon Networks, depending on which network the associated TLD exists within. Owners of Web3 Domains, and yourself as a Web3 TLD owner, can opt to bridge all levels of Decentraweb Domains, Ethereum -> Polygon or Polygon -> Ethereum, at any time by using our Domains Bridge ()

To provide Web3 Domain Registrations (e.g absolutely.anything) from your Web3 TLD(s) (e.g .anything) on your own platform, website or dApp, please ensure that you have registered and staked your Web3 TLD(s) within our

All write operations return instance of ethers.js class. You can call transaction.wait(n) to wait until transaction get n confirmations.

Decentraweb domain supports setting wallet addresses for multiple cryptocurrencies. Decentraweb is compatible with ENS () and uses package to encode/decode wallet addresses.

Full list of supported cryptocurrencies can be found in documentation.

DNS records are stored in binary format known as DNS Wireformat. This library utilize package to encode/decode DNS data. This library exports RecordSet utility class to help with encoding/decoding.

Decentraweb domains support storing content hash. This feature is following ENS standard. Supported content hash URL formats:

⚒️
🚀
ethers Provider
ethers Signer
ethers.js
Read Guide
DNS Platform
TransactionResponse
EIP-2304
@ensdomains/address-encoder
@ensdomains/address-encoder
dns-packet
EIP-1577
Logonpm: @decentraweb/corenpm
@decentraweb/core - v2.3.0 | Decentraweb Packages - v1.0.0