Skip to content

[BUG] Decouple Wallet from BaseContractInteraction #18754

@shiqicao

Description

@shiqicao

What are you trying to do?

BaseContractInteraction should be chain/wallet agnostic, send method can take wallet as parameter

Code Reference

export abstract class BaseContractInteraction {
  protected log = createLogger('aztecjs:contract_interaction');

  constructor(
    protected wallet: Wallet,
    protected authWitnesses: AuthWitness[] = [],
    protected capsules: Capsule[] = [],
  ) {}

  /**
   * Returns an execution request that represents this operation.
   * Can be used as a building block for constructing batch requests.
   * @param options - An optional object containing additional configuration for the transaction.
   * @returns An execution request wrapped in promise.
   */
  public abstract request(options?: RequestInteractionOptions): Promise<ExecutionPayload>;

  // docs:start:send
  /**
   * Sends a transaction to the contract function with the specified options.
   * This function throws an error if called on a utility function.
   * It creates and signs the transaction if necessary, and returns a SentTx instance,
   * which can be used to track the transaction status, receipt, and events.
   * @param options - An object containing 'from' property representing
   * the AztecAddress of the sender and optional fee configuration
   * @returns A SentTx instance for tracking the transaction status and information.
   */
  public send(options: SendInteractionOptions): SentTx {
    // docs:end:send
    const sendTx = async () => {
      const executionPayload = await this.request(options);
      const sendOptions = await toSendOptions(options);
      return this.wallet.sendTx(executionPayload, sendOptions);
    };
    return new SentTx(this.wallet, sendTx);
  }
}

Aztec Version

v3.0.0-devnet.5

OS

No response

Browser (if relevant)

No response

Node Version

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions