buildSignAndEncodeRaw method

Future<HexString> buildSignAndEncodeRaw({
  1. required Signer signer,
  2. required HexString to,
  3. BigInt? value,
  4. Uint8List? data,
  5. List<AuthorizationTuple> authorizationList = const [],
})

Builds, signs, and encodes a complete EIP-7702 transaction into a raw hex string suitable for submission via eth_sendRawTransaction.

This helper performs the full transaction pipeline:

  1. Constructs an Unsigned7702Tx using buildUnsigned.
  2. Signs the transaction using signUnsigned and the provided Signer.
  3. Serializes the signed transaction via parseRawTransaction.

The resulting hex string contains the typed transaction prefix (0x04) followed by the RLP-encoded body and is ready for broadcast to any JSON-RPC node.

Parameters:

  • signer — the signer producing the ECDSA signature.
  • to — the destination address of the transaction.
  • value — optional ether value to transfer.
  • data — optional calldata payload.
  • authorizationList — one or more previously constructed AuthorizationTuple values to include in the EIP-7702 authorizationList field.

Example:

final raw = await builder.buildSignAndEncodeRaw(
  signer: signer,
  to: recipient,
  data: myCallData,
);
await client.sendRawTransaction(raw);

Implementation

Future<HexString> buildSignAndEncodeRaw({
  required Signer signer,
  required HexString to,
  BigInt? value,
  Uint8List? data,
  List<AuthorizationTuple> authorizationList = const [],
}) async {
  final unsignedTx = await buildUnsigned(
    sender: signer.ethPrivateKey.address.eip55With0x,
    to: to,
    value: value,
    data: data,
    authorizationList: authorizationList,
  );

  final signedTx = await signUnsigned(signer: signer, unsignedTx: unsignedTx);
  final rawTx = parseRawTransaction(signedTx, chainId: ctx.chainId?.toInt());
  return rawTx;
}