Skip to content
LogoLogo

virtualAddress.registerMaster

Registers the caller as a virtual address master. Learn more about virtual addresses

The salt must satisfy a 32-bit proof-of-work requirement: keccak256(address, salt)[0:4] must be zero. Use VirtualMaster.mineSaltAsync from viem/tempo to find a valid salt.

Usage

import { VirtualMaster } from 'viem/tempo'
import { client } from './viem.config'
 
const result = await VirtualMaster.mineSaltAsync({
  address: client.account.address,
})
 
const { receipt, masterId, masterAddress } = 
  await client.virtualAddress.registerMasterSync({ salt: result!.salt })
 
console.log('Master ID:', masterId)
Master ID: 0x58e21090
console.log('Master address:', masterAddress)
Master address: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

Asynchronous Usage

The example above uses a *Sync variant of the action, that will wait for the transaction to be included before returning.

If you are optimizing for performance, you should use the non-sync virtualAddress.registerMaster action and wait for inclusion manually:

import { Actions, VirtualMaster } from 'viem/tempo'
import { client } from './viem.config'
 
const result = await VirtualMaster.mineSaltAsync({
  address: client.account.address,
})
 
const hash = await client.virtualAddress.registerMaster({
  salt: result!.salt,
})
const receipt = await client.waitForTransactionReceipt({ hash })
 
const { args } 
  = Actions.virtualAddress.registerMaster.extractEvent(receipt.logs)

Mining a Salt

Use VirtualMaster.mineSaltAsync from ox/tempo to find a valid proof-of-work salt. It uses WASM-accelerated keccak256 with parallel workers:

import { VirtualMaster } from 'viem/tempo'
 
const result = await VirtualMaster.mineSaltAsync({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
})
 
console.log('Salt:', result?.salt)
console.log('Master ID:', result?.masterId)

Return Type

type ReturnType = {
  /** The 4-byte master identifier */
  masterId: Hex
  /** The registered master address */
  masterAddress: Address
  /** Transaction receipt */
  receipt: TransactionReceipt
}

Parameters

salt

  • Type: Hex

The 32-byte salt that satisfies the proof-of-work requirement.

account (optional)

  • Type: Account | Address

Account that will be used to send the transaction.

feeToken (optional)

  • Type: Address | bigint

Fee token for the transaction.

Can be an unpaused USD-denominated TIP-20 token address or ID. Use client.fee.validateToken({ token }) to validate a token before submitting a transaction or setting it as a fee preference.

feePayer (optional)

  • Type: Account | true

Fee payer for the transaction.

Can be a Viem Account, or true if a Fee Payer Service will be used.

gas (optional)

  • Type: bigint

Gas limit for the transaction.

maxFeePerGas (optional)

  • Type: bigint

Max fee per gas for the transaction.

maxPriorityFeePerGas (optional)

  • Type: bigint

Max priority fee per gas for the transaction.

nonce (optional)

  • Type: number

Nonce for the transaction.

nonceKey (optional)

  • Type: 'expiring' | bigint

Nonce key for the transaction. Use 'expiring' to use expiring nonces (TIP-1009), which enables concurrent transaction submission without nonce ordering.

validBefore (optional)

  • Type: number

Unix timestamp before which the transaction must be included.

validAfter (optional)

  • Type: number

Unix timestamp after which the transaction can be included.

throwOnReceiptRevert (optional)

  • Type: boolean
  • Default: true

Whether to throw an error if the transaction receipt indicates a revert. Only applicable to *Sync actions.