The RegistryContract is a wrapper for the native contract that encapsulates the necessary logic for interacting with it. It provides the following methods:
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:
Copy import { RegistryContract } from ' @bako-id/sdk ' ;
const contract = RegistryContract . create ( provider ) ; 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.
Copy await contract . register ( {
domain ,
period ,
resolver ,
} ) ; The method receives an object of type RegisterPayload with the following properties:
The handle name. Valid characters: A-Z, a-z, 0-9 @_
The number of years for the handle.
The resolver address of the handle.
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()
This method encapsulates the logic for transferring the ownership of the name to another address.
The method receives an object of type ChangeAddressPayloadarrow-up-right with the following properties:
The handle name. Valid characters: A-Z, a-z, 0-9, @_
The address of the new owner of the handle.
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()
Change resolver
This method encapsulates the logic for changing the resolver address of the handle.
The method receives an object of type ChangeAddressPayloadarrow-up-right with the following properties:
The handle name. Valid characters: A-Z, a-z, 0-9, @_
The address of the new resolver for the handle.
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()
This method encapsulates the logic for adding metadata to the handle.
The handle name. Valid characters: A-Z, a-z, 0-9, @_
Record<MetadataKeys, string>
The keys and values of the metadata to be included.
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')
This method retrieves all the metadata for a handle.
The handle name. Valid characters: A-Z, a-z, 0-9, @_
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')
Last updated 8 months ago