我正在使用带有醚库的本地草帽节点为我的合同开发UI。我有几个不同的契约函数调用,它们在浏览器控制台中成功传递并且没有抛出任何错误,但是它们在运行节点的VSC终端窗口中抛出了一个"Error: Transaction reverted: function未被识别并且没有回退函数“
就像这样:
eth_feeHistory
eth_blockNumber
eth_getBalance (9)
eth_feeHistory
eth_getTransactionCount (2)
eth_sendRawTransaction
Contract call: Betting#appendUserBet
Transaction: 0xb4f3b2277d18a7fcdb26ef6c85c770dd2f03c25d7e197f2a99356ec5d4a9213f
From: 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc
To: 0x5fbdb2315678afecb367f032d93f642f64180aa3
Value: 0.427 ETH
Gas used: 62365 of 62852
Block #14: 0x9b3b289e7c5ebfc69c223dfcf26effac42bb0485ce75f19d83565e394e32668e
eth_call
Contract call: Betting#<unrecognized-selector>
From: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
To: 0x5fbdb2315678afecb367f032d93f642f64180aa3
Error: Transaction reverted: function selector was not recognized and there's no fallback function
at Betting.<unrecognized-selector> (contracts/Betting.sol:4)
at HardhatNode.runCall (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\provider\node.ts:616:20)
at EthModule._callAction (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\provider\modules\eth.ts:354:9)
at HardhatNetworkProvider._sendWithLogging (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:139:22)
at HardhatNetworkProvider.request (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\provider\provider.ts:116:18)
at JsonRpcHandler._handleRequest (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:188:20)
at JsonRpcHandler._handleSingleRequest (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:167:17)
at Server.JsonRpcHandler.handleHttp (C:\Users\Sabotage\Desktop\code\betting_platform\node_modules\hardhat\src\internal\hardhat-network\jsonrpc\handler.ts:52:21)具有相关函数的契约的代码片段:
contract Betting {
uint256 public fee = 1000000000000000000 wei;
struct UserStruct {
uint256 betAmount;
uint256 potentialWinnings;
string teamChosen;
}
mapping(address => UserStruct) public userStructs;
address[] public userList;
function appendUserBet(string memory userTeamChosen) public payable {
uint256 minimumFee = 1 * 10**17 wei;
userList.push(payable(msg.sender));
require(msg.value >= minimumFee);
fee = msg.value;
userStructs[msg.sender].betAmount += msg.value;
userStructs[msg.sender].teamChosen = userTeamChosen;
}
}在js中调用此函数的脚本片段:
import { ethers } from "./ethers-5.6.esm.min.js"
import { abi, contractAddress } from "./constants.js"
async function appendUserBet() {
const ethAmount = document.getElementById("ethAmount").value
console.log(`Funding with ${ethAmount}...`)
if (typeof window.ethereum !== "undefined") {
const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()
const contract = new ethers.Contract(contractAddress, abi, signer)
try {
const transactionResponse = await await contract.appendUserBet(
"kek",
{
value: ethers.utils.parseEther(ethAmount)
}
)
await listenForTransactionMine(transactionResponse, provider)
} catch (error) {
console.log(error)
}
} else {
appendBetButton.innerHTML = "Please install MetaMask"
}
}契约还有其他功能,但是当其中任何一个执行时,即使执行是100%成功,也会抛出此错误。我的密码怎么了?如何修复此错误?
提前谢谢你的时间!
发布于 2022-07-07 09:58:27
如果有人遇到同样的问题,就忽略它吧。我没有发现任何解决方案,而且代码仍然运行得非常好。
发布于 2023-05-29 23:25:03
到目前为止,我找到了一个行之有效的解决办法。我遇到了Error: Transaction reverted: function selector was not recognized and there's no fallback function问题,只是“有时”,没有任何明显的原因,而其他时候,一切都很完美。因此,我在我的retries文件中向mocha添加了hardhat.config选项:
mocha: {
timeout: 100000000,
retries: 3,
},希望能帮上忙。
https://ethereum.stackexchange.com/questions/130583
复制相似问题