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,
vaultsContractId: config.VAULTS_CONTRACT_ID,
valuesDatabaseContractId: config.DB_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
}
}
Set, read and remove data from a Domain
const tx = await sdk.setDomainData({
node: SorobanDomainsSDK.parseDomain({ domain: 'fcm' }),
key: DefaultStorageKeys.TOML,
value: ['String', 'https://raw.githubusercontent.com/Stellar-Corium/FCM-sc/refs/heads/main/stellar.toml'],
source: 'ACCOUNT_SIGNER',
});
// ... Sign the transaction and submit to the network
In this example, we can see how to sign the TOML
key using a String value which in this case is the URL where the file can be fetched.
Now let's read it and then remove it:
const data = await sdk.getDomainData({
node: SorobanDomainsSDK.parseDomain({ domain: 'fcm' }),
key: DefaultStorageKeys.TOML,
});
// ... Do something with the data
const tx = await sdk.removeDomainData({
node: SorobanDomainsSDK.parseDomain({ domain: 'fcm' }),
key: DefaultStorageKeys.TOML,
source: 'ACCOUNT_SIGNER',
});
// ... Sign the transaction and submit to the network
Please check the SDK repository in order to check all the types and error classes available.