Web3 Revert Message - solidity

I am using web3 over the Rinkeby test network for my solidity project. I am trying to get the exact revert message, using the error object.
try{
await contract.methods.acceptBattle(id).send({
from: address,
value:val
});
return '';
}
catch(e){
console.log(e.message);
}
After the code is running in the catch block, I am getting the output in the following format:
execution reverted: This battle isn't exist.
0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b426174746c65206e7
56d6265722069736e27742065786973742e0a0000000000
Is there a way to get only the message itself (in the first row) and not the address coming after?
As I saw in Do all Ethereum networks return the revert reasons as a “message” field?
and since I am running over the Rinkeby test network, the address supposed to be part of the data field of the error and not part of the message.
This is the relevant code for the revert message:
function acceptBattle(uint256 battle_id) public payable{
Battle storage bate=battleInfo[battle_id];
require(bate.amountBet>0, "Battle number isn't exist.\n");
require(bate.creator!=msg.sender, "Impossible to fight against yourself.");
require(bate.creator==bate.opponent, "This battle is closed, opponent already exist.");
require(msg.value==bate.amountBet, "Betting value isn't as specified for this battle.");
bate.opponent=msg.sender;
}

Related

HardHat - Fail - Unable to verify / Etherscan

Here's my contract.
// SPDX-License-Identifier: MIT
pragma solidity >= 0.7.3;
contract terceiroTest {
// We pass and old String, a new string and when this event is
// broadcast everybody is able to see that the even happened.
// and see the strings exposed too.
event UpdatedMessages(string oldStr, string newStr);
string public message;
// When this contract is deployed we require an argument passed called initMessasge
constructor (string memory initMessage) {
message = initMessage;
}
function update(string memory newMessage) public {
string memory oldMsg = message;
message = newMessage;
emit UpdatedMessages(oldMsg, newMessage);
}
}
and it gives me the error:
I've tried to find any kind of description about this error, even changed solidity's version. I'm studying about smartcontracts still, if someone having or had the same error I would apretiate for enlighting me. Thanks.
I have had similar problems and they all resolved by themselves. It is possible that there is no issue in your code and the issue is with etherscan.
Here are a few things I recommend to triage:
Submit again
Give gap between submission and verification
Try a different env like polygonscan.
Manually submit from their UI.
I took your contract and tested it in my hardhat env. Everything worked fine. Maybe there's something else happening in your local setup?
Try again with a fresh hardhat setup. Try using this 'badass hardhat setup' https://github.com/mistersingh179/badass-hardhat-setup
I used that setup as a clean slate, started my localhost chain, and then connected that to my sidekik interface to test the functions. Your code works fine. Example here:

Error: missing revert data in call exception on tokenOfOwnerByIndex and tokenByIndex from openzeppelin ERC721Enumerable

I'm getting a odd error across several calls out to openzeppelin that
Error: missing revert data in call exception; Transaction reverted without a reason string
I didn't change anything and am using out of the box openzeppelin and minimal test harness code
contract MyToken is ERC721Enumerable
This works fine and I successfully call several internal functions from my tests like
const totalSupply = await myTokenContract.totalSupply();
const ownerBalance = await myTokenContract.balanceOf(owner.address);
these both work just fine
However, when calling functions like tokenOfOwnerByIndex or tokenByIndex I get that Error
const ownerToken = await myTokenContract.tokenOfOwnerByIndex(
owner.address, ethers.BigNumber.from(1).toNumber()
);
const ownerToken = await myTokenContract.tokenOfOwnerByIndex(
owner.address, 1
);
const firstToken = await myTokenContract.tokenByIndex(1);
These each produce the same error that
Error: missing revert data in call exception; Transaction reverted without a reason string
I'm assuming it's some environmental configuration issue but I can't quite seem to figure it out?
hardhat 2.9.3, openzeppelin/contracts 4.6.0, solidity 0.8.1

How to show firebase auth error messages different in UI

I am using the firebase auth now I want to show a different message in UI for every error message
You have to check for specific error messages in your catch block and add custom handling.
You don't mention the language you're working in (and I'm not familiar with all of the different libraries), but C# will throw a FirebaseAuthException containing the property AuthErrorCode which is an enum representing the error. You could check that in, say, a switch statement to get the required message.
try {
userRecord = await _FirebaseAuth.GetUserByEmailAsync(email, token)
.ConfigureAwait(false);
}
catch (FirebaseAuthException ex) {
if (ex.AuthErrorCode == AuthErrorCode.UserNotFound) {
DisplayError($"Error retrieving user record for {email}");
}
}

Solidity: The transaction has been reverted to the initial state

I have a separate function openTrading()
function openTrading() external onlyOwner() {
require(!tradingOpen,"trading is already open");
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
}
This was working fine few days ago. Now it is failing, debugging in JVM reveals it is failing at
_uniswapV2Router.factory()
Error:
The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
I am completely lost, no idea why something that was working earlier now failing. To test this, I copied old deployed contract and it failed exact same place.
Could someone please suggest me how to resolve this issue?

Example Oraclize files return 0: string: when called in Remix

I want to use Oraclize in Remix, to test it. I'm too stupid to use their examples.
How can I make this work?
From their Github I took the YouTube-Views code and copied it into Remix
pragma solidity >= 0.5.0 < 0.6.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract YoutubeViews is usingOraclize {
string public viewsCount;
event LogYoutubeViewCount(string views);
event LogNewOraclizeQuery(string description);
constructor()
public
{
update(); // Update views on contract creation...
}
function __callback(
bytes32 _myid,
string memory _result
)
public
{
require(msg.sender == oraclize_cbAddress());
viewsCount = _result;
emit LogYoutubeViewCount(viewsCount);
// Do something with viewsCount, like tipping the author if viewsCount > X?
}
function update()
public
payable
{
emit LogNewOraclizeQuery("Oraclize query was sent, standing by for the answer...");
oraclize_query("URL", 'html(https://www.youtube.com/watch?v=9bZkp7q19f0).xpath(//*[contains(#class, "watch-view-count")]/text())');
}
}
When I use the viewCount it returns:
0: string:
This happens with all the other examples aswell.
With WolframAlpha eg. I also get the following error:
transact to WolframAlpha.update errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value. Debug the transaction to get more information.
Ok you don't see the answer like a normal result in Remix:
You have to go under settings and open the Oraclize plug in.
If you then deploy the contract and or click update, you get the result shown in the plug in.