发布于 2022-06-10 14:50:04
文档并不是最新的,您可以使用maxPriorityFeePerGas和maxFeePerGas,没有问题.
gas是您愿意为tx花费的最大气体量,它必须用于每种类型的事务:0类型(遗留)、1 (使用访问列表)和2 (EIP-1559)。
为了方便起见,您可以找到web3.js 在回购中和下面的事务的完整定义:
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;
}如果设置了maxPriorityFeePerGas和maxFeePerGas,并且设置了gasPrice参数,则为它们都将被设置为等于gasPrice。
有关许多使用示例,请参见官方回购中的测试用例,如下所示。搜索postEip1559Block以查看包含maxPriorityFeePerGas和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);
});
});发布于 2022-06-10 13:27:12
sendSignedTransaction函数不接收gasPrice或gas,有参数-
web3.eth.sendSignedTransaction(signedTransactionData [, callback])因此,您可以在maxFeePerGas中指定signTransaction并使用sendSignedTransaction发送。
var Tx = require('@ethereumjs/tx').Transaction;
var privateKey = Buffer.from('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex');
var rawTx = {
nonce: '0x00',
maxFeePerGas: '0x09184e72a000',
maxPriorityFeePerGas: '0x1C9C380'
gasLimit: '0x2710',
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}
var tx = new Tx(rawTx, {'chain':'ropsten'});
tx.sign(privateKey);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);https://ethereum.stackexchange.com/questions/129703
复制相似问题