如何更改以太币.js中默认的tx费用上限,以避免出现类似"tx fee (4.0 ether) exceeds the configured cap (1.00 ether)"的错误



我正在尝试执行智能合约批处理功能,但过了一段时间后,我收到了以下错误:

processing response error (body="{"jsonrpc":"2.0","id":52,"error":{"code":-32000,"message":"tx fee (4.00 ether) exceeds the configured cap (1.00 ether)"}}", error={"code":-32000}, requestBody="{"method":"eth_sendRawTransaction",

我确实在寻找同样的东西,并得到了一个链接:tx费(2.11以太(超过了配置的上限(1.00以太(,如何绕过默认上限?但答案是特定于本地网络和geth的,我正在使用Ethers.js对多边形和雪崩c链网络进行调用,并想知道如何在默认提供者中更改默认配置。以下是代码:

async function createTransactionData(arg: any[]) {
const transferABI = ["function batchSafeMint(address toAddress, uint256[] tokenIds, string[] uris)"];
const transferInterface = new ethers.utils.Interface(transferABI);
const transferData = transferInterface.encodeFunctionData(
'batchSafeMint',
[
arg[0],
arg[1],
arg[2]
]
);
return transferData
}
const transferData = await createTransactionData(params)
const provider = new ethers.providers.JsonRpcProvider(network.networkURL)
const gasFeeData = await provider.getFeeData();
const nonce = await provider.getTransactionCount(senderAddress);
const chainId = (await provider.getNetwork()).chainId;
const rawTxn: any = {
to: contractHash,
maxFeePerGas: gasFeeData.maxFeePerGas,
maxPriorityFeePerGas: gasFeeData.maxPriorityFeePerGas,
chainId: chainId,
data: transferData,
gasPrice: null,
nonce: nonce,
value: null,
from: senderAddress,
type: 2
}
rawTxn["gasLimit"] = await provider.estimateGas(rawTxn)
delete rawTxn["from"]
const unsignedTxn = await ethers.utils.resolveProperties(rawTxn);
const keccak256Hash = await getUnsignedTxnKeccak256Hash(unsignedTxn);
const signedTxn = await signer.sign(keccak256Hash); // implemented own signer

const signedTxnRaw = ethers.utils.serializeTransaction(
//@ts-ignore
<UnsignedTransaction>unsignedTxn,
signedTxn
);
const receipt = await provider.sendTransaction(signedTxnRaw);
let result = await provider.waitForTransaction(receipt.hash);

因此,在创建提供程序时,我看到了提供ConnectionInfo对象的选项。


// Exported Types
export type ConnectionInfo = {
url: string,
headers?: { [key: string]: string | number }
user?: string,
password?: string,
allowInsecureAuthentication?: boolean,
allowGzip?: boolean,
throttleLimit?: number,
throttleSlotInterval?: number;
throttleCallback?: (attempt: number, url: string) => Promise<boolean>,
skipFetchSetup?: boolean;
errorPassThrough?: boolean;
timeout?: number,
};

我可以使用配置params来更改默认配置吗?

您需要使用另一个节点或运行自己的节点,而不限制--rpc.txfeecap

您正在使用的节点似乎具有--rpc.txfeecap默认值,即1.0 ethers。

抱歉,您无法在ethers.js或JavaScript代码中解决此问题。

最新更新