GetMintTransactionParameters

GetMintTransactionParameters function

GetMintTransactionParameters is a function which generates all the required parameters needed to send a successfull transaction and mint a subname on a given chain

Usage

index.ts
const listedName = await NamespaceClient.getListedName("example.eth", sepolia.id);
const minterAddress = "0x3E1e131E7e613D260F809E6BBE6Cbf7765EDC77f";
const subnameLabel = "hello";

const transactionParameters = await NamespaceClient
        .getMintTransactionParameters(listedName, {
                minterAddress,
                subnameLabel,
                subnameOwner: minterAddress
        });

Optionally, we can also provide records object so that we can mint a subname and set records in the same transaction

index.ts
const listedName = await NamespaceClient.getListedName("example.eth", sepolia.id);
const minterAddress = "0x3E1e131E7e613D260F809E6BBE6Cbf7765EDC77f";
const subnameLabel = "hello";

const transactionParameters = await NamespaceClient
        .getMintTransactionParameters(listedName, {
                minterAddress,
                subnameLabel,
                subnameOwner: minterAddress,
                records: {
                    texts: [ { key: "name", value: "John" } ],
                    addresses: [ { coinType: 60, address: minterAddress } ],
                    contenthash: "0x0" 
                }
        });

Return Type

This function returns parameters which can be used to mint a subname on a given chain:

export interface MintTransactionParameters {
  abi: Abi,
  contractAddress: Address
  functionName: string
  args: any[]
  value: bigint
  chain: Chain
}

Assuming we use Viem as a client for performing blockchain operations, we can use MintParameters to send a mint transaction

index.ts
import { createWalletClient, http } from "viem";
import { base } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

const listedName = await NamespaceClient.getListedName("example.eth", sepolia.id);
const minterAddress = "0x3E1e131E7e613D260F809E6BBE6Cbf7765EDC77f";
const subnameLabel = "hello";

const transactionParameters = await NamespaceClient
        .getMintTransactionParameters(listedName, {
           minterAddress,
           subnameLabel,
           subnameOwner: minterAddress
        });
        
const wallet = privateKeyToAccount("0x0my-priv-key")
const walletClient = createWalletClient({
  transport: http(),
  chain: base,
  account: wallet
})

const transactionHash = await walletClient.writeContract({
  abi: transactionParameters.abi,
  args: transactionParameters.args,
  address: transactionParameters.contractAddress,
  functionName: transactionParameters.functionName,
  value: transactionParameters.value;
});

Last updated