Skip to content

wallet_prepareCreateAccount

Prepares an account creation.

Accounts created using the RPC server use PREP to generate an address. Using PREP, it is proven that no one knows the Secp256k1 private key of the account, even the RPC server.

Keys

There exists three different key roles:

  • Admin keys are capable of adding and modifying other keys, and capable of spending an unlimited amount of tokens and calling any contract and selector.
  • Normal keys can only call contracts as defined by the permissions set on it, and spend the amount of tokens afforded to it by permissions.
  • Session keys are like normal keys, except they also have an expiry.

Setting permissions on an admin key is not allowed and will return an error.

For complete details on keys, including their signature encoding, public key encoding, and key hashes, refer to the Key section.

Selectors

Selectors for call permissions can either be a 4-byte selector, e.g. 0x12345678, or a Solidity-style selector, like transfer(address,uint256).

 cast sig "transfer(address,uint256)"
 
# 0xa9059cbb

Request

type Request = {
  method: 'wallet_prepareCreateAccount',
  params: [{
    capabilities: {
      authorizeKeys: {
        // See "Keys"
        key: {
          expiry?: number,
          type: 'p256' | 'webauthnp256' | 'secp256k1',
          role: 'admin' | 'normal' | 'session',
          publicKey: `0x${string}`,
        },
        permissions: ({
          type: 'call',
          // See "Selectors"
          selector: string,
          to: `0x${string}`,
        } | {
          type: 'spend',
          limit: number,
          period: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year',
          // defaults to the native token (address zero)
          token?: `0x${string}`,
        })[],
      }[],
      // the contract the account should delegate to
      delegation: `0x${string}`,
    },
    chainId: `0x${string}`,
  }],
}

Response

type Response = {
  context: {
    account: {
      address: `0x${string}`,
      signedAuthorization: {
        // usually 0 to allow for replayability
        chainId: `0x${string}`,
        // the contract the account delegates to
        address: `0x${string}`,
        nonce: `0x${string}`,
        yParity: `0x${string}`,
        r: `0x${string}`,
        s: `0x${string}`,
      },
      // the salt used to generate the prep account
      salt: number,
      // calls performed on account creation
      initCalls: {
        to: `0x${string}`,
        value: `0x${string}`,
        bytes: `0x${string}`,
      }[],
    },
    chainId: `0x${string}`,
  },
  // the address of the account
  address: `0x${string}`,
  // digests that need to be signed by each admin key
  digests: `0x${string}`[],
  // capabilities assigned to the account
  capabilities: {
    authorizeKeys: {
      // key hash
      hash: `0x${string}`,
      // See "Keys"
      key: {
        expiry?: number,
        type: 'p256' | 'webauthnp256' | 'secp256k1',
        role: 'admin' | 'normal' | 'session',
        publicKey: `0x${string}`,
      },
      permissions: ({
        type: 'call',
        // See "Selectors"
        selector: string,
        to: `0x${string}`,
      } | {
        type: 'spend',
        limit: number,
        period: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year',
        // defaults to the native token (address zero)
        token?: `0x${string}`,
      })[],
    }[],
    // the contract the account delegates to
    delegation: `0x${string}`,
  },
}