Skip to content
LogoLogo

Account.fromConfig

Instantiates an Account for a configurable account. Omit address or set it to infer to derive the canonical CREATE2 account address. After the config changes, use the stable address and pass the current config fields.

Owners can be local accounts, addresses, or weighted owner entries. Direct owners have a weight of 1, and threshold defaults to 1.

Local owner accounts are retained so the returned account can aggregate their approvals when you call signTransaction. Address-only owners support distributed signing, where each owner signs the same prepared request and the sender supplies the resulting signatures.

Usage

import { Account } from 'viem/tempo'
 
const owner_1 = Account.fromSecp256k1(
  '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
)
const owner_2 = Account.fromSecp256k1(
  '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d'
)
 
const account = Account.fromConfig({
  address: 'infer',
  owners: [owner_1, owner_2],
  threshold: 2,
})
 
console.log('Address:', account.address)

Account.fromConfig normalizes the config with AccountConfig.from, including canonical owner ordering. The initial config always uses version 0.

Current Config

After a config update, reconstruct the account from its stable address and current config. The address does not change when the config changes.

import { Account } from 'viem/tempo'
 
const account = Account.fromConfig({
  address: '0x0000000000000000000000000000000000000001',
  owners: [
    '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
  ],
  salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
  threshold: 2,
  version: 1,
})

Tempo stores the config commitment, not the config fields. Retain each current config or recover it from the account's ConfigurableAccountConfigUpdated events.

Upgraded Account

For an account upgraded in place with accounts.upgrade, pass the upgraded address and the owners and threshold it installed as upgrade.

import { Account } from 'viem/tempo'
 
const account = Account.fromConfig({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  upgrade: {
    owners: ['0x70997970C51812dc3A010C7d01b50e0d17dc79C8'],
    threshold: 1,
  },
})

The upgrade installs version 1 of the account's config. After a later config update, use the current config fields instead.

Address Only

Use an address-only account when only the stable account identity is needed.

import { Account } from 'viem/tempo'
 
const account = Account.fromConfig(
  '0x0000000000000000000000000000000000000001'
)

An address-only account contains no config or local owner keys. A coordinated client can load the current config from its store. Otherwise, provide the config through { address, ...config } before sending.

External Owners

Pass addresses when owner approvals are collected outside the current process.

import { Account } from 'viem/tempo'
 
const account = Account.fromConfig({
  address: 'infer',
  owners: [
    '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
    '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
  ],
  threshold: 2,
})

Weighted Owners

Pass { owner, weight } entries to give owners different approval weights.

import { Account } from 'viem/tempo'
 
const owner = Account.fromSecp256k1(
  '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
)
 
const account = Account.fromConfig({
  address: 'infer',
  owners: [
    { owner, weight: 2 },
    { owner: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8', weight: 1 },
  ],
  threshold: 2,
})

Return Type

type ReturnType = ConfigurableAccount
 
type ConfigurableAccount = LocalAccount<'configurable'> & {
  /** Normalized config, when supplied. */
  config: AccountConfig.Config | undefined
  /** @internal Local owner accounts retained for signing. */
  owners: readonly LocalAccount[]
}

The account's signTransaction method combines retained local owner approvals with any approvals provided through the request's signatures. sign, signMessage, and signTypedData are not supported.

Parameters

value

  • Type: Account.fromConfig.Parameters

An initial config, a stable address with its current config, an upgraded address with its installed owners, or an address without a retained config.

value.address

  • Type: 'infer' | Address | undefined

Omit this field or set it to infer to derive an account from a version-zero config. For a current config, pass the account's stable address. Pass an Address as value when no config is needed.

value.factory

  • Type: Address
  • Default: Addresses.configurableAccountRecoveryFactory

The recovery factory used to derive the address from an initial config. Only set it for a chain configured with a different factory.

import { Account } from 'viem/tempo'
 
const account = Account.fromConfig({
  address: 'infer',
  factory: '0x9999999999999999999999999999999999999999', 
  owners: ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'],
})

value.owners

  • Type: readonly (Address | LocalAccount | { owner: Address | LocalAccount; weight: number })[]

The config owners. Passing a local account makes that account available for local aggregation. Passing an address keeps that owner's approval external.

value.salt

  • Type: Hex
  • Default: 0x0000000000000000000000000000000000000000000000000000000000000000

The 32-byte config salt. This field is optional for an initial config and required for a current config.

value.threshold

  • Type: number
  • Default: 1

The total owner weight required to authorize an operation. This field is optional for an initial config and required for a current config.

value.upgrade

  • Type: { owners: readonly (Address | LocalAccount | { owner: Address | LocalAccount; weight: number })[]; threshold?: number }

The owners and threshold installed by accounts.upgrade. Pass it with the upgraded account's address, instead of owners, salt, threshold, and version.

import { Account } from 'viem/tempo'
 
const account = Account.fromConfig({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  upgrade: { 
    owners: ['0x70997970C51812dc3A010C7d01b50e0d17dc79C8'], 
    threshold: 1, 
  }, 
})
value.upgrade.owners
  • Type: readonly (Address | LocalAccount | { owner: Address | LocalAccount; weight: number })[]

The owners installed by the upgrade. Passing a local account makes it available for local aggregation.

import { Account } from 'viem/tempo'
 
const account = Account.fromConfig({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  upgrade: {
    owners: ['0x70997970C51812dc3A010C7d01b50e0d17dc79C8'], 
    threshold: 1,
  },
})
value.upgrade.threshold
  • Type: number
  • Default: 1

The approval weight installed by the upgrade.

import { Account } from 'viem/tempo'
 
const account = Account.fromConfig({
  address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  upgrade: {
    owners: ['0x70997970C51812dc3A010C7d01b50e0d17dc79C8'],
    threshold: 1, 
  },
})

value.version

  • Type: bigint | number

The nonzero current config version. For an initial config, omit this field or pass 0 when spreading a normalized AccountConfig.Config value.