20 provider.estimateGas方法咨询

const tx = { to: "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD", data: "0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000006686a2ff00000000000000000000000000000000000000000000000000000000000000040a00060400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000001600000000000000000000000004a029f7bcf33acb03547d8fa7be840347973e24e000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000066ae2d9e00000000000000000000000000000000000000000000000000000000000000030000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad000000000000000000000000000000000000000000000000000000006686a7a600000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000004178f6cc15e06ebf0a0709cbaf1a0218cbb1b650c6c47f72bf69b2ccba4c4580a875ee96e25cb000505d128839746fbcd39c3ad1c7bb35d598506e42255ed900da1b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000a968163f0a57b4000000000000000000000000000000000000000000000000000000000000008dfc03800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000424a029f7bcf33acb03547d8fa7be840347973e24e002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000064dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000000000fee13a103a10d593b9ae06b3e05f2e7e1c00000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000060000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000008dfc038", value: '0x00' }; provider.estimateGas(tx).then(res => { console.log('estimated gas', res); }).catch(err => { console.log('estimated error', err); }) 上边代码运行后,会发生异常,shortMessage: 'execution reverted (unknown custom error)'。 【0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD】是Universal Router合约地址。

有朋友知道具体是什么原因吗?谢谢您

请先 登录 后评论

最佳答案 2024-07-16 17:48

看来还是你的data 有问题,你看下能你使用的参数是不是能解析出来,慢慢调

const { ethers } = require("ethers");

// 合约 ABI
const contractABI = [
  // 合约的 ABI
];

// 方法签名
const methodSignature = "YOUR_METHOD_NAME(uint256, address, ...)";
const methodID = ethers.utils.id(methodSignature).slice(0, 10);

// 检查 data 的前四个字节是否匹配方法签名
if (data.startsWith(methodID)) {
  console.log("Method ID matches");
} else {
  console.error("Method ID does not match");
}

// 解码参数
const iface = new ethers.utils.Interface(contractABI);
const decodedData = iface.decodeFunctionData(methodSignature, data);

console.log(decodedData);
请先 登录 后评论

其它 3 个回答

Yootou
请先 登录 后评论
Wade - Footprint Analytics CTO
  擅长:数据分析,GameFi,NFT
请先 登录 后评论
Yootou
请先 登录 后评论
  • 3 关注
  • 0 收藏,1435 浏览
  • Yootou 提出于 2024-07-10 10:16