diff --git a/backend/mpc-system/services/service-party-app/src/pages/Home.tsx b/backend/mpc-system/services/service-party-app/src/pages/Home.tsx
index ed72ee0a..fe02c7ce 100644
--- a/backend/mpc-system/services/service-party-app/src/pages/Home.tsx
+++ b/backend/mpc-system/services/service-party-app/src/pages/Home.tsx
@@ -317,8 +317,8 @@ export default function Home() {
};
// 格式化 gas 费用显示
- const formatGasFee = (gasLimit: bigint, maxFeePerGas: bigint): string => {
- const maxFee = gasLimit * maxFeePerGas;
+ const formatGasFee = (gasLimit: bigint, gasPrice: bigint): string => {
+ const maxFee = gasLimit * gasPrice;
const feeKava = Number(maxFee) / 1e18;
return feeKava.toFixed(8).replace(/\.?0+$/, '');
};
@@ -583,7 +583,7 @@ export default function Home() {
预估 Gas 费
- ~{formatGasFee(preparedTx.gasLimit, preparedTx.maxFeePerGas)} KAVA
+ ~{formatGasFee(preparedTx.gasLimit, preparedTx.gasPrice)} KAVA
diff --git a/backend/mpc-system/services/service-party-app/src/utils/transaction.ts b/backend/mpc-system/services/service-party-app/src/utils/transaction.ts
index d11483e9..f6b301cb 100644
--- a/backend/mpc-system/services/service-party-app/src/utils/transaction.ts
+++ b/backend/mpc-system/services/service-party-app/src/utils/transaction.ts
@@ -335,33 +335,37 @@ export async function getNonce(address: string): Promise {
/**
* 通过 RPC 获取当前 gas 价格
+ * 使用 eth_gasPrice 方法获取 Legacy 交易的 gasPrice
*/
export async function getGasPrice(): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }> {
const rpcUrl = getCurrentRpcUrl();
- // 获取基础费用
- const blockResponse = await fetch(rpcUrl, {
+ // 使用 eth_gasPrice 获取建议的 gas 价格
+ const response = await fetch(rpcUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
- method: 'eth_getBlockByNumber',
- params: ['latest', false],
+ method: 'eth_gasPrice',
+ params: [],
id: 1,
}),
});
- const blockData = await blockResponse.json();
- const baseFeePerGas = blockData.result?.baseFeePerGas
- ? BigInt(blockData.result.baseFeePerGas)
- : BigInt(1000000000); // 默认 1 gwei
+ const data = await response.json();
+ let gasPrice: bigint;
- // 优先费用设为 1 gwei
- const maxPriorityFeePerGas = BigInt(1000000000);
- // 最大费用 = 基础费用 * 2 + 优先费用
- const maxFeePerGas = baseFeePerGas * 2n + maxPriorityFeePerGas;
+ if (data.result) {
+ gasPrice = BigInt(data.result);
+ // 增加 10% 以确保交易能被打包
+ gasPrice = gasPrice * 110n / 100n;
+ } else {
+ // 默认 1 gwei
+ gasPrice = BigInt(1000000000);
+ }
- return { maxFeePerGas, maxPriorityFeePerGas };
+ // 为了兼容性,同时返回 maxFeePerGas (实际上用作 gasPrice)
+ return { maxFeePerGas: gasPrice, maxPriorityFeePerGas: gasPrice };
}
/**