在truffle环境下如何才能让revert的交易一定上链(强制发起交易)

在truffle环境下发送一笔合约调用(合约调用内一定会revert),使用await web3.eth.sendTransaction()发送交易。交易不会上链,直接在命令行中提示 Error: execution reverted 在truffle环境下如何才能让revert的交易一定上链

请先 登录 后评论

最佳答案 2022-06-01 14:20

如果要强制发起只要是直接用 rpc 发起请求, 因为 sdk 通常会做一些预检查,以便用户损失。

例如使用 ethers 发起交易:

const iface = new Iface(NFTXMarketplaceZap);
const data = iface.encodeFunctionData("methodName", [ params ])
const tx = [{
  "from": "0xa",
  "to": "0xb",
  "gas": "0xf93E0", // ~1000000
  "gasPrice": "0x3B9ACA00", // 1 gwei
  "value": "0xa",
  "data": data
}]

signer.send('eth_sendTransaction', params).then((tx) => {
  console.log('transactionHash is ' + tx);
})
请先 登录 后评论

其它 0 个回答