Registry Contract
The RegistryContract
is a wrapper for the native contract that encapsulates the necessary logic for interacting with it. It provides the following methods:
register
: Mints a new handle.changeOwner
: Transfers ownership.changeResolver
: Sets a new resolver address.setMetadata
: Sets new metadata.getMetadata
: Retrieves the metadata of a handle.
To create an instance, you need to import the module from @bako-id/sdk
and call the constructor method. This method accepts either a Provider
or an Account
:
import { RegistryContract } from '@bako-id/sdk';
const contract = RegistryContract.create(provider);
Register
This method encapsulates the logic for registering a new handle by validating whether the handle name follows a valid string pattern, adding the necessary funds for the transaction, ensuring that the resolver address is either an Address
or a Contract ID
, and executing the contract call.
await contract.register({
domain,
period,
resolver,
});
Parameters
The method receives an object of type RegisterPayload
with the following properties:
domain
string
The handle name. Valid characters: A-Z, a-z, 0-9 @_
period
number
The number of years for the handle.
resolver
string
The resolver address of the handle.
Validations
The method throw an error when:
The contract is not connected to an account:
throw new Error('Account is required to register a domain')
The name of handle have invalid chars:
throw new InvalidDomainError()
The account not have sufficient funds:
throw new NotFoundBalanceError()
Output
Promise<{
gasUsed: BN,
transactionId: string,
transactionResult: TransactionResult<TransactionType.Script>,
transactionResponse: TransactionResponse,
assetId: string
}>;
Change owner
This method encapsulates the logic for transferring the ownership of the name to another address.
await contract.changeOwner({
domain,
address,
});
Parameters
The method receives an object of type ChangeAddressPayload
with the following properties:
domain
string
The handle name. Valid characters: A-Z, a-z, 0-9, @_
address
string
The address of the new owner of the handle.
Validations
The method throw an error when:
The contract is not connected to an account:
throw new Error('Account is required to register a domain')
The name of handle have invalid chars:
throw new InvalidDomainError()
Output
Promise<
TransactionResult<TransactionType.Script>
>;
Change resolver
This method encapsulates the logic for changing the resolver address of the handle.
await contract.changeResolver({
domain,
address,
});
Parameters
The method receives an object of type ChangeAddressPayload
with the following properties:
domain
string
The handle name. Valid characters: A-Z, a-z, 0-9, @_
address
string
The address of the new resolver for the handle.
Validations
The method throw an error when:
The contract is not connected to an account:
throw new Error('Account is required to register a domain')
The name of handle have invalid chars:
throw new InvalidDomainError()
Output
Promise<
TransactionResult<TransactionType.Script>
>;
Set metadata
This method encapsulates the logic for adding metadata to the handle.
import { MetadataKeys } from '@bako-id/sdk';
const metadata = {
[MetadataKeys.CONTACT_EMAIL]: 'random@gmail.com',
[MetadataKeys.CONTACT_NICKNAME]: 'random',
[MetadataKeys.CONTACT_PHONE]: '123456789',
[MetadataKeys.LINK_BLOG]: 'https://random.com',
};
await contract.setMetadata(domain, metadata);
Parameters
domain
string
The handle name. Valid characters: A-Z, a-z, 0-9, @_
metadata
Record<MetadataKeys, string>
The keys and values of the metadata to be included.
Validations
The method throw an error when:
The contract is not connected to an account:
throw new Error('Account is required to register a domain')
The name of handle have invalid chars:
throw new InvalidDomainError()
The handle is not registered
throw new Error('Domain not found')
Output
Promise<boolean>;
Get metadata
This method retrieves all the metadata for a handle.
await contract.getMetadata(domain);
Parameters
domain
string
The handle name. Valid characters: A-Z, a-z, 0-9, @_
Validations
The method throw an error when:
The name of handle have invalid chars:
throw new InvalidDomainError()
The handle is not registered
throw new Error('Domain not found')
Output
Promise<Record<MetadataKeys, string | undefined>>;
Last updated