Solidity/React Query: Utilizing Ethers.js, I am making an attempt 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 undertaking, but it surely would not appear to be working for no matter motive. 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 wonderful.
The React:
const check = useContractReader(writeContracts, "YourContract", "getTest", "1", "0"); // Indexing recreation 1, gamers 0
operate getTestName() {
if (check == null) {
return "check is undefined.";
} else if (check[0] == null) { // check[0] is the identify variable within the struct
return "noName";
} else {
return check[0].toString();
}
}
The Solidity code:
struct Recreation {
deal with host; // Establishes host operate entry 0
uint gameId; // Permits totally different video games to be performed concurrently 1
uint buyinRequirement; // To ascertain minimal buyin quantity for a recreation 2
uint etherWithdrawalReqs; // Tracks # of ether in complete from requests. If >/< than contract stability, throws error 3
uint gamePot; // Tracks how a lot ether is within the recreation's pot 4
uint8 tableWithdrawalReqs; // Tracks what number of gamers have requested a withdrawal 5
uint8 playerCount; // Tracks # of of gamers in a recreation 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 recreation struct is already completed 9
deal with[] playerList; // 10
}
struct Participant {
string identify; // Permits gamers to extra simply determine 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 every one withdrawal requests look good at desk
bool hasWithdrawn; // To indicate {that a} participant has paidout to forestall triggering of any features after they receieve again their funds
bool isInGame; // Is in recreation bool
bool isHost; // Is host
}
mapping(deal with => Participant) public playerInfo; // To name Participant struct primarily based on the msg.sender
// Mapping for finding every recreation's particulars
mapping(uint => Recreation) public idToGame; // To name Recreation struct to see recreation particulars
operate getTest(uint gameId, uint playerIndex) public view returns (Participant reminiscence) {
return playerInfo[idToGame[gameId].playerList[playerIndex]];
}
Please discuss with my stack overflow query for extra info on the problem:
https://stackoverflow.com/questions/74323524/problem-accessing-solidity-getter-using-ethers-js






