Bako Docs
  • Welcome
  • Developers
    • ID
      • Architecture
      • Contracts
      • SDK
        • Quickstart
        • Bako ID Client
        • Registry Contract
Powered by GitBook
On this page
  • Register
  • Parameters
  • Validations
  • Output
  • Change owner
  • Parameters
  • Validations
  • Output
  • Change resolver
  • Parameters
  • Validations
  • Output
  • Set metadata
  • Parameters
  • Validations
  • Output
  • Get metadata
  • Parameters
  • Validations
  • Output
  1. Developers
  2. ID
  3. SDK

Registry Contract

PreviousBako ID Client

Last updated 16 days ago

The RegistryContract is a wrapper for the native contract that encapsulates the necessary logic for interacting with it. It provides the following methods:

  • : Mints a new handle.

  • : Transfers ownership.

  • : Sets a new resolver address.

  • : Sets new metadata.

  • : 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:

parameter
type
description

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

parameter
type
description

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

parameter
type
description

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

parameter
type
description

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

parameter
type
description

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>>;

The method receives an object of type with the following properties:

The method receives an object of type with the following properties:

ChangeAddressPayload
ChangeAddressPayload
register
changeOwner
changeResolver
setMetadata
getMetadata