Space ID
What is Space ID?
Space ID is a name service that allows users to replace the complex contract address with a meaningful and memorable domain.
It's very similar to the DNS from Web2, you may treat Space ID as the DNS, and the contract address is equivalent to the IP address. By using the domain name, it can be resolved to the actual servers' IP address, and the traffic can be redirected accordingly.
How to use Space ID to access a smart contract?
Space ID name resolving service is mainly running on two smart contracts, the "SID Registry" and the "Public Resolver".
Every domain(e.g fr.boracle.bnb) will convert into a node-hash value first, then we use it to query the SID Registry to know which Public Resolver we should visit, finally we can get the contract address we need from the Public Resolver by providing the same node-hash value.
An example is given as follows, let's say we are going to access the Feed Registry Contract with the help of Space ID:
- JavaScript
import namehash from 'eth-ens-namehash'
const feedRegistrySID = 'fr.boracle.bnb'
const feedRegistryNodeHash = namehash.hash(feedRegistrySID)
console.log(feedRegistryNodeHash)
The output should be 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff.
The node-hash value and the address of the SID Registry are remain unchanged.
- Solidity
- JavaScript
import "./SIDRegistry.sol";
import "./PublicResolver.sol";
contract MyContract {
// ......
// You may simply copy this function and use it
// replace the nodeHash value with the another one
function getFeedRegistryAddress() internal returns (address memory) {
bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
SIDRegistry sidRegistry = SIDRegistry(sidRegistryAddress);
address publicResolverAddress = sidRegistry.resolver(nodeHash);
PublicResolver publicResolver = PublicResolver(publicResolverAddress);
return publicResolver.addr(nodeHash);
}
// ......
}
import { ethers } from 'hardhat'
async function getFeedRegistryAddress() {
const nodeHash = '0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff'
const sidRegistryAddress = '0xfFB52185b56603e0fd71De9de4F6f902f05EEA23'
const sidRegistry = await ethers.getContractAt('SIDRegistry', sidRegistryAddress)
const publicResolverAddress = await sidRegistry['resolver(bytes32 node)'](nodeHash)
const publicResolver = await ethers.getContractAt('PublicResolver', publicResolverAddress)
return await resolver['addr(bytes32)'](nodeHash)
}
Get SIDRegistry.sol and PublicResolver.sol here which is including in the Binance Oracle Repository.
The SID Registry has different address in the BSC Mainnet and the BSC Testnet.
- BSC Mainet
- BSC Testnet
0x08CEd32a7f3eeC915Ba84415e9C07a7286977956
0xfFB52185b56603e0fd71De9de4F6f902f05EEA23
See the full example
Download the full code and try it out from this GitHub Repo.