ethers-provider-flashbots-bundle icon indicating copy to clipboard operation
ethers-provider-flashbots-bundle copied to clipboard

signBundle doesn't set correct chainId when passed a FlashbotsBundleTransaction

Open danielattilasimon opened this issue 4 years ago • 2 comments

signBundle() can take a mix of FlashbotsBundleTransactions and FlashbotsBundleRawTransactions. In the case of FlashbotsBundleTransaction, the user provides an (unsigned) TransactionRequest and a Signer. signBundle() populates certain fields of the transaction in case they're missing, like: nonce, gasPrice, gasLimit; however it doesn't include chainId, which ends up being 0 even on Görli.

To be fair, the testnet example does explicitly set chainId to 5, however it could still make sense to automatically populate chainId, either using the Signer's getChainId() method or its populateTransaction(). Notably: when using a Contract's populateTransaction.XXX methods, chainId will be missing from the resulting object.

danielattilasimon avatar Dec 16 '21 08:12 danielattilasimon

i am observing the same issue. anybody aware of any workarounds?

lexomis avatar Dec 18 '21 00:12 lexomis

i am observing the same issue. anybody aware of any workarounds?

I decided to populate and sign the transaction before passing it to signBundle like this:

const transaction = await this._contract.populateTransaction.someFunc(
  /* ... parameters ... */,
  {
    nonce: this._signer.getTransactionCount("latest") // ignore pending TXs
  }
);

const populatedTransaction = await this._signer.populateTransaction(transaction);
const signedTransaction = await this._signer.signTransaction(populatedTransaction);
const signedBundle = await this._bundleProvider.signBundle([{ signedTransaction }]);

Alternatively, you could also just set chainId before passing the TransactionRequest to signBundle:

const transaction = await this._contract.populateTransaction.someFunc(/* ... parameters ... */);
transaction.chainId = await this._signer.getChainId();

const signedBundle = await this._bundleProvider.signBundle([{
  transaction,
  signer: this._signer
}]);

danielattilasimon avatar Dec 21 '21 08:12 danielattilasimon