Skip to content

How to send EIP712, EIP1559 transaction request #200

@mthinh

Description

@mthinh

Hi, I'm integrating to Lens.xyz, and need to trigger some EIP712, EIP1559 transaction. They actually have sdk for web but not Flutter yet. I check their sdk's repo and found this.
I wonder how we handle to send EIP712/EIP1559 transaction to wallet app. Sorry but I'm new to these one.

Normally, here's how I send normal transaction

Future<String> requestTransaction({
    required String chainId,
    required EthereumTransaction transaction,
  }) async {
    await switchChain(chainId: chainId);

    await Future.delayed(const Duration(milliseconds: 500));
    _w3mService.launchConnectedWallet();

    final transactionId = await _w3mService.request(
      topic: _w3mService.session?.topic ?? '',
      chainId: chainId,
      request: SessionRequestParams(
        method: 'eth_sendTransaction',
        params: [
          transaction.copyWith(data: transaction.data ?? '').toJson(),
        ],
      ),
    );
    if (transactionId is! String) {
      throw Exception('Failed to send transaction ${transactionId.toString()}');
    }
    return transactionId;
  }

@freezed
class EthereumTransaction with _$EthereumTransaction {
  EthereumTransaction._();

  @JsonSerializable(includeIfNull: false)
  factory EthereumTransaction({
    required String from,
    required String to,
    required String value,
    String? nonce,
    String? gasPrice,
    String? maxFeePerGas,
    String? maxPriorityFeePerGas,
    String? gas,
    String? gasLimit,
    String? data,
  }) = _EthereumTransaction;
}

Here's how there SDK send transaction

import { sendTransaction as sendEip1559Transaction, waitForTransactionReceipt } from 'viem/actions';
import { sendEip712Transaction } from 'viem/zksync';

async function sendTransaction(
  walletClient: WalletClient<Transport, chains.LensChain, Account>,
  request: SponsoredTransactionRequest | SelfFundedTransactionRequest,
): Promise<Hash> {
  invariant(
    walletClient.account.address === request.raw.from,
    `Account mismatch: ${walletClient.account} !== ${request.raw.from}`,
  );

  if (request.__typename === 'SponsoredTransactionRequest') {
    return sendEip712Transaction(walletClient, {
      account: walletClient.account,
      data: request.raw.data,
      gas: BigInt(request.raw.gasLimit),
      maxFeePerGas: BigInt(request.raw.maxFeePerGas),
      maxPriorityFeePerGas: BigInt(request.raw.maxPriorityFeePerGas),
      nonce: request.raw.nonce,
      paymaster: request.raw.customData.paymasterParams?.paymaster,
      paymasterInput: request.raw.customData.paymasterParams?.paymasterInput,
      to: request.raw.to,
      value: BigInt(request.raw.value),
    });
  }

  return sendEip1559Transaction(walletClient, {
    account: walletClient.account,
    data: request.raw.data,
    gas: BigInt(request.raw.gasLimit),
    maxFeePerGas: BigInt(request.raw.maxFeePerGas),
    maxPriorityFeePerGas: BigInt(request.raw.maxPriorityFeePerGas),
    nonce: request.raw.nonce,
    to: request.raw.to,
    type: 'eip1559',
    value: BigInt(request.raw.value),
  });
}

Metadata

Metadata

Assignees

Labels

appkitAppKit related issueawaiting customerFurther information has been requestedhelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions