Skip to content

wallet_prepareCalls

Prepares a call bundle.

It returns a digest of the call bundle to sign over, as well as the parameters required to fulfil a wallet_sendPreparedCalls request (context).

Request

type Request = {
  method: 'wallet_prepareCalls',
  params: [{
    /** Calls to prepare. */
    calls: {
      /** Recipient. */
      to: `0x${string}`;
      /** Calldata. */
      data?: `0x${string}`;
      /** Value to transfer. */
      value?: `0x${string}`;
    }[];
    /** 
     * Chain ID to send the calls to.
     * If not provided, the current chain will be used.
     */
    chainId?: `0x${string}`;
    /**
     * Key that will be used to sign over the digest.
     */
    key: {
      publicKey: `0x${string}`,
      type: 'address' | 'secp256k1' | 'p256' | 'webauthn-256'
    };
    /** 
     * Address of the account to send the calls from.
     * If not provided, the Account will be filled by the Wallet.
     */
    from?: `0x${string}`;
  }]
}

Response

type Response = {
  /** Chain ID the calls were prepared for. */
  chainId: `0x${string}`;
  /** 
   * Data to be forwarded to `wallet_sendPreparedCalls`.
   */
  context: unknown;
  /** Digest to sign over. */
  digest: `0x${string}`;
  /**
   * Key that will be used to sign over the digest.
   */
  key: {
    publicKey: `0x${string}`;
    type: 'address' | 'secp256k1' | 'p256' | 'webauthn-256';
  };
}

Example

import { Porto } from 'porto'
 
const { provider } = Porto.create()
 
const response = await provider.request({ 
  method: 'wallet_prepareCalls', 
  params: [{ 
    calls: [{ 
      to: '0xcafebabecafebabecafebabecafebabecafebabe', 
      value: '0x12345678', 
    }], 
    key: { 
      publicKey: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', 
      type: 'p256'
    }, 
  }] 
})