Quick start
Using Relation Protocol's NameService contract as an example, we will demonstrate how to quickly access the contract.
Prepare the environment
To complete this tutorial successfully, you must have Node.js and MetaMask installed on your machine.
To create a project, we will use vite 's react template.
npm create vite@latest my-app -- --template react
cd my-app
npm installInstall ethers.js to interact with the contract.
npm install ethers@5Import the abi file
Create an abi.json file under the "src" directory, the content of which can be founded on Relation Protocol's list of resources.
import the file in App.jsx
import abi from './abi.json'Call a contract
Import "ethers" and create a method "getContractInstance" to acquire a "contract" instance so that it can be used to call a contract. Note that the contract in this example is deployed on the mumbai network, so make sure that Metamask is switched to this network.
import { ethers, providers } from 'ethers'
// The name to be registered
const registerName = 'test-' + Date.now()
const getContractInstance = () => {
// The contract address
const contractAddress = '0x6A22794A1e2aBdEC057a6dc24A6BFB53F9518016'
const provider = new providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()
const contract = new ethers.Contract(contractAddress, abi, signer)
return contract
}Write methods for registration and querying.
The complete App.jsx is as follows:
Run the project
Open http://localhost:5173/ in your browser.
Last updated