Skip to main content

Front-end integration

Front-end integration is easy and you can either use our simple SDK or have your own solution because in simple terms you only need to ask the contract if one domain is registered. In order to make this process easy, we created an SDK (public repository can be found here). Here is how you use it:

Installation

npm i @creit.tech/sorobandomains-sdk

The SorobanDomainsSDK class

The first step will be creating a new instance from the main class.

import * as SDK from '@stellar/stellar-sdk';
import config from './myconfigfile.ts'

const sdk: SorobanDomainsSDK = new SorobanDomainsSDK({
stellarSDK: SDK,
rpc: new SDK.SorobanRpc.Server(config.RPC_URL),
network: config.NETWORK,
contractId: config.CONTRACT_ID,
defaultFee: config.DEFAULT_FEE,
defaultTimeout: config.DEFAULT_TIMEOUT,
simulationAccount: config.SIMULATION_ACCOUNT,
});

Fetch a registered domain

import { Record } from '@creit.tech/sorobandomains-sdk';

const domainRecord: Record = await sdk.searchDomain({ domain: 'jhon' });
const subDomainRecord: Record = await sdk.searchDomain({ domain: 'jhon', subDomain: 'payments' });

When searching for a domain, you can receive two types of errors: an expected error by the SDK or a simulation error. Currently, there is only one expected error by the SDK: Domain404Error.

If you need to catch this type of error you can do this:

import { Domain404Error } from '@creit.tech/sorobandomains-sdk';

try {
const domainRecord: Record = await sdk.searchDomain({ domain: 'nonexistingrecord' });
} catch (e) {
if (e.name === Domain404Error.name) {
// ... Do something here
} else {
// ... Do this instead
}
}

Please check the SDK repository in order to check all the types and error classes available.