Skip to content

Account.from

Instantiates a delegated account from an address or account parameters.

Usage

From Address

import { Account } from 'porto/viem'
 
const account = Account.from('0x742d35Cc6634C0532925a3b8D2c88F65b5c92B23') 

From Account Parameters

import { Account, Key } from 'porto/viem'
 
const passkey = await Key.createWebAuthnP256({
  label: 'My Passkey',
})
 
const account = Account.from({ 
  address: '0x742d35Cc6634C0532925a3b8D2c88F65b5c92B23', 
  keys: [passkey], 
}) 

With Custom Sign Function

import { Account } from 'porto/viem'
 
const account = Account.from({ 
  address: '0x742d35Cc6634C0532925a3b8D2c88F65b5c92B23', 
  async sign({ hash }) { 
    // Custom signing logic 
    return '0x...'
  }, 
}) 

Parameters

parameters

  • Type: string | AccountParameter

Either an address string or an account parameter object.

type AccountParameter = {
  /** Account address */
  address: `0x${string}`
  
  /** Optional array of keys associated with the account */
  keys?: readonly Key.Key[] | undefined
  
  /** Optional custom signing function */
  sign?: (args: { hash: `0x${string}` }) => Promise<`0x${string}`> | `0x${string}`
  
  /** Account source type */
  source?: 'porto' | 'privateKey' | undefined
}

Return Value

type Account = LocalAccount & {
  /** Account address */
  address: `0x${string}`
  
  /** Optional array of keys associated with the account */
  keys?: readonly Key.Key[] | undefined
  
  /** Required signing function */
  sign: (args: { hash: `0x${string}` }) => Promise<`0x${string}`> | `0x${string}`
  
  /** Account source */
  source: 'porto' | 'privateKey'
}

Returns a Porto Account that extends Viem's LocalAccount with additional Porto-specific properties.