The documentation is not up-to-date, you can use maxPriorityFeePerGas
and maxFeePerGas
without problem.
gas
is the maximum amount of gas you are willing to spend for the tx, and it must be used for every type of transaction: type 0
(legacy), 1
(using access list) and 2
(EIP-1559).
You can find the complete definition of transaction for web3.js in the repo, and below for your convenience:
export interface TransactionConfig {
from?: string | number;
to?: string;
value?: number | string | BN;
gas?: number | string;
gasPrice?: number | string | BN;
maxPriorityFeePerGas?: number | string | BN;
maxFeePerGas?: number | string | BN;
data?: string;
nonce?: number;
chainId?: number;
common?: Common;
chain?: string;
hardfork?: string;
}
If maxPriorityFeePerGas
and maxFeePerGas
are set, and the gasPrice
parameter is set, they will be both set equal to gasPrice
.
See the test cases in the official repo for many examples of use, like the one below. Search for postEip1559Block
to see examples that contain maxPriorityFeePerGas
and maxFeePerGas
.
it("signTransaction must compare to eth_signTransaction", function(done) {
var provider = new FakeHttpProvider();
var web3 = new Web3(provider);
provider.injectResult(
test.transaction.common.hardfork === 'london' ?
postEip1559Block:
preEip1559Block
);
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_getBlockByNumber');
assert.deepEqual(payload.params, ['latest', false]);
});
provider.injectResult('0x5022');
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_gasPrice');
assert.deepEqual(payload.params, []);
});
var ethAccounts = new Accounts(web3);
var testAccount = ethAccounts.privateKeyToAccount(test.privateKey);
assert.equal(testAccount.address, test.address);
testAccount.signTransaction(test.transaction).then(function (tx) {
assert.equal(tx.messageHash, test.messageHash, "message hash failed");
assert.equal(tx.transactionHash, test.transactionHash, "tx hash failed");
assert.equal(tx.rawTransaction, test.rawTransaction, "rawtx failed");
done();
})
.catch(e => {
console.log(i, e)
done(e);
});
});
gasPrice
is supposed to do ?