buildAndSignIfNeeded method
Builds and signs a new authorization tuple only if the EOA is not already delegated to the configured implementation.
This method:
- Checks the current delegation state using isDelegatedTo.
- If the EOA already delegates to Eip7702Context.delegateAddress,
returns
null. - Otherwise, invokes buildAndSign to produce a new AuthorizationTuple.
This helper is typically used when preparing a type 0x04
EIP-7702 transaction to ensure that delegation is applied only when
necessary.
Example:
final tuple = await builder.buildAndSignIfNeeded(signer: signer);
if (tuple == null) {
print('Delegation already active; no authorization needed.');
}
See also:
Implementation
Future<AuthorizationTuple?> buildAndSignIfNeeded({
required Signer signer,
Executor? executor,
}) async {
final alreadyDelegating = await isDelegatedTo(
signer.ethPrivateKey.address,
ctx.delegateAddress,
);
if (alreadyDelegating) return null;
return buildAndSign(signer: signer, executor: executor);
}