# 调用智能合约报错分析小技巧 Error: execution reverted **Published by:** [Bot80926](https://paragraph.com/@bot80926/) **Published on:** 2023-05-04 **URL:** https://paragraph.com/@bot80926/error-execution-reverted ## Content 调用智能合约报错分析小技巧 Error: execution revertedBot80926 于 2023-04-29 22:46:03 首次发布 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。前端在调试调用合约的时候经常会遇到合约revert的情况,大部分区块浏览器只会显示 execution reverted,并不会把具体原因告诉我们。这个时候一般会去找合约大哥帮忙分析错误,但是合约大哥是怎么分析报错的呢? 这篇文章给你一个解题方法。直接上代码const main = async (txHash) => { const tx = await provider.getTransaction(txHash) if (!tx) { console.log('tx not found') } else { const code = await provider.call(tx) console.log('revert reason:', code) } } 测试:main('0x5ac9e43a32a651e92cff884a38b910d4a1897578bd935430057a619f27b7a21d')可以看到测试txHash被revert的原因是 输入了无效的 B Amount,也就给我们提供的 debug 的思路。 该方法试用于所有evm链,只需修改 provider 对应链的chain信息即可。 完整代码地址:仓库地址 五一休假的第四篇产出。完结 🎉 ~ ## Publication Information - [Bot80926](https://paragraph.com/@bot80926/): Publication homepage - [All Posts](https://paragraph.com/@bot80926/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@bot80926): Subscribe to updates