网络不支持EIP-1559:claimFaucet()转账失败问题求助
问题:调用
claimFaucet()函数时抛出"Network doesn't support eip-1559"错误 环境背景
- 自定义以太坊网络,RPC连接方式:
const web3 = new Web3('http://146.190.XXX.XX:8546') - Metamask可正常执行代币生成、网络代币转账、合约调用操作,Web3 RPC也支持合约执行
错误现象
调用claimFaucet()函数进行网络代币转账时,抛出错误:
Network doesn't support eip-1559
涉事函数代码
claimFaucet = async function (toAddress, pKey) { // body... const myAddress = '0xaC7E9A085A5D13d5C38XXXXXXXXXXXXXXXXXXXX' //TODO: replace this address with your own public address const nonce = await web3.eth.getTransactionCount(myAddress, 'latest'); const transaction = { 'to': toAddress, // faucet address to return eth 'value': 10000000000000000, 'gas': 426144, 'maxFeePerGas': 10000000000, 'nonce': nonce }; console.log(nonce,transaction) const signedTx = await web3.eth.accounts.signTransaction(transaction, pKey); await web3.eth.sendSignedTransaction(signedTx.rawTransaction, function(error, hash){ console.log(hash) return; }); }
创世文件内容
{ "config": { "chainId": 416, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "eip1559Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, "istanbulBlock": 0 }, "alloc" : { "0xF58bCF53e07a4f85e872346Ce603D2269Cc5Bb67": {"balance":"510000000000000000000000000"}, "0xa583Eb6b4c29e047996D03Db2CC86573E16233c6": {"balance":"800000000000000000000000000"} }, "coinbase" : "0x0000000000000000000000000000000000000000", "difficulty" : "0x100000", "extraData" : "", "gasLimit" : "0x1000000", "nonce" : "0x0000000000000042", "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp" : "0x00" }
解决方法
问题根源是交易参数使用了EIP-1559格式的maxFeePerGas,但当前网络实际未完全支持EIP-1559(Metamask会自动适配网络格式,手动构造交易则不会)。只需修改交易参数为传统格式即可:
- 修改交易对象,移除
maxFeePerGas,替换为gasPrice参数:
const transaction = { 'to': toAddress, 'value': 10000000000000000, 'gas': 426144, 'gasPrice': 10000000000, // 替换原maxFeePerGas 'nonce': nonce };
- 原理:改用
gasPrice后,交易将以Legacy Transaction格式发送,完全适配当前网络的配置,避免EIP-1559兼容性问题。
内容的提问来源于stack exchange,提问作者Debo Karmakar
相关产品推荐
相关产品推荐

