Solidity/React Query: Utilizing Ethers.js, I am attempting to entry a operate taking in two variables as parameters utilizing the hook useContractReader. I replicated it from different useContractReader code I’ve in my mission, nevertheless it would not appear to be working for no matter purpose. I assume it has to do with some parsing of the variables I’ve, however how I do it in different issues, it really works effective.
The React:
const take a look at = useContractReader(writeContracts, "YourContract", "getTest", "1", "0"); // Indexing sport 1, gamers 0
operate getTestName() {
if (take a look at == null) {
return "take a look at is undefined.";
} else if (take a look at[0] == null) { // take a look at[0] is the identify variable within the struct
return "noName";
} else {
return take a look at[0].toString();
}
}
The Solidity code:
struct Recreation {
deal with host; // Establishes host operate entry 0
uint gameId; // Permits completely different video games to be performed concurrently 1
uint buyinRequirement; // To determine minimal buyin quantity for a sport 2
uint etherWithdrawalReqs; // Tracks # of ether in whole from requests. If >/< than contract steadiness, throws error 3
uint gamePot; // Tracks how a lot ether is within the sport's pot 4
uint8 tableWithdrawalReqs; // Tracks what number of gamers have requested a withdrawal 5
uint8 playerCount; // Tracks # of of gamers in a sport 6
uint8 verifiedWithdrawalReqs; // Tracks # of verifs that withdrawal requests are legitimate 7
bool endedBuyin; // Host operate to finish buyin stage 8
bool isActive; // Checks if sport struct is already performed 9
deal with[] playerList; // 10
}
struct Participant {
string identify; // Permits gamers to extra simply establish eachother
uint gameId; // gameId generated from gameNumber
uint buyinAmount; // How a lot a participant has purchased in with
uint withdrawalAmount; // How a lot a participant has requested a withdrawal for
bool withdrawalReq; // Tracks if a participant has submitted a request
bool verifyReqs; // TO confirm that each one withdrawal requests look good at desk
bool hasWithdrawn; // To suggest {that a} participant has paidout to stop triggering of any capabilities after they receieve again their funds
bool isInGame; // Is in sport bool
bool isHost; // Is host
}
mapping(deal with => Participant) public playerInfo; // To name Participant struct based mostly on the msg.sender
// Mapping for finding every sport's particulars
mapping(uint => Recreation) public idToGame; // To name Recreation struct to see sport particulars
operate getTest(uint gameId, uint playerIndex) public view returns (Participant reminiscence) {
return playerInfo[idToGame[gameId].playerList[playerIndex]];
}
Please check with my stack overflow query for extra data on the problem:
https://stackoverflow.com/questions/74323524/problem-accessing-solidity-getter-using-ethers-js