Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/web3-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,7 @@ Documentation:
### Changed

- Added parameter `customTransactionReceiptSchema` into methods `emitConfirmation`, `waitForTransactionReceipt`, `watchTransactionByPolling`, `watchTransactionBySubscription`, `watchTransactionForConfirmations` (#7000)

### Fixed

- Fixed issue with simple transactions, Within `checkRevertBeforeSending` if there is no data set in transaction, set gas to be `21000` (#7043)
9 changes: 8 additions & 1 deletion packages/web3-eth/src/utils/send_tx_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,14 @@ export class SendTxHelper<

public async checkRevertBeforeSending(tx: TransactionCall) {
if (this.options.checkRevertBeforeSending !== false) {
const reason = await getRevertReason(this.web3Context, tx, this.options.contractAbi);
let formatTx = tx;
if (isNullish(tx.data) && isNullish(tx.input) && isNullish(tx.gas)) { // eth.call runs into error if data isnt filled and gas is not defined, its a simple transaction so we fill it with 21000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when data is populated, is gas limit always populated in that case?

Copy link
Contributor

@jdevcs jdevcs May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and its only missing in case of value transfers eth_calls only?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additionally, if tx has gas limit only for eth_call rpc( for revert check) and not in actual Tx that will be sent after it,
eth_call may pass while actual Tx may fail in some cases, as both will differ, so I think gas limit should be applied in all cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eth_call with no data and no gas will fail from provider, but send_transaction gas will be filled automatically. i belive this is just a weird edge case, and with our tests passing i dont believe this will be an issue.

formatTx = {
...tx,
gas: 21000
}
}
const reason = await getRevertReason(this.web3Context, formatTx, this.options.contractAbi);
if (reason !== undefined) {
throw await getTransactionError<ReturnFormat>(
this.web3Context,
Expand Down
23 changes: 23 additions & 0 deletions packages/web3-eth/test/unit/send_tx_helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
JsonRpcResponse,
TransactionReceipt,
Web3BaseWalletAccount,
TransactionCall
} from 'web3-types';
import { Web3Context, Web3EventMap, Web3PromiEvent } from 'web3-core';
import {
Expand Down Expand Up @@ -151,6 +152,28 @@ describe('sendTxHelper class', () => {
expect(f).toHaveBeenCalledWith(error);
promiEvent.off('error', f);
});

it('add gas to simple transaction in checkRevertBeforeSending', async () => {
const _sendTxHelper = new SendTxHelper({
web3Context,
promiEvent: promiEvent as PromiEvent,
options: {
checkRevertBeforeSending: true,
},
returnFormat: DEFAULT_RETURN_FORMAT,
});

const tx = {from:"0x"} as TransactionCall

await _sendTxHelper.checkRevertBeforeSending(tx);

const expectedTx = {
...tx,
gas: 21000,
};
expect(utils.getRevertReason).toHaveBeenCalledWith(web3Context, expectedTx, undefined);

});
it('emit handleError with handleRevert', async () => {
const error = new ContractExecutionError({ code: 1, message: 'error' });
web3Context.handleRevert = true;
Expand Down