MultiversX Tracker is Live!

Solidity/React issue when using Ethers.js

Etherum Reddit

More / Etherum Reddit 102 Views

Solidity/React Question: Using Ethers.js, I'm trying to access a function taking in two variables as parameters using the hook useContractReader. I replicated it from other useContractReader code I have in my project, but it doesn't seem to be working for whatever reason. I assume it has to do with some parsing of the variables I have, but how I do it in other problems, it works fine.

The React:

const test = useContractReader(writeContracts, "YourContract", "getTest", "1", "0"); // Indexing game 1, players 0 function getTestName() { if (test == null) { return "test is undefined."; } else if (test[0] == null) { // test[0] is the name variable in the struct return "noName"; } else { return test[0].toString(); } } 

The Solidity code:

struct Game { address host; // Establishes host function access 0 uint gameId; // Allows different games to be played concurrently 1 uint buyinRequirement; // To establish minimum buyin amount for a game 2 uint etherWithdrawalReqs; // Tracks # of ether in total from requests. If >/< than contract balance, throws error 3 uint gamePot; // Tracks how much ether is in the game's pot 4 uint8 tableWithdrawalReqs; // Tracks how many players have requested a withdrawal 5 uint8 playerCount; // Tracks # of of players in a game 6 uint8 verifiedWithdrawalReqs; // Tracks # of verifs that withdrawal requests are valid 7 bool endedBuyin; // Host function to end buyin stage 8 bool isActive; // Checks if game struct is already done 9 address[] playerList; // 10 } struct Player { string name; // Allows players to more easily identify eachother uint gameId; // gameId generated from gameNumber uint buyinAmount; // How much a player has bought in with uint withdrawalAmount; // How much a player has requested a withdrawal for bool withdrawalReq; // Tracks if a player has submitted a request bool verifyReqs; // TO verify that all withdrawal requests look good at table bool hasWithdrawn; // To signify that a player has paidout to prevent triggering of any functions after they receieve back their funds bool isInGame; // Is in game bool bool isHost; // Is host } mapping(address => Player) public playerInfo; // To call Player struct based on the msg.sender // Mapping for locating each game's details mapping(uint => Game) public idToGame; // To call Game struct to see game details function getTest(uint gameId, uint playerIndex) public view returns (Player memory) { return playerInfo[idToGame[gameId].playerList[playerIndex]]; } 

Please refer to my stack overflow question for more information on the issue:

https://stackoverflow.com/questions/74323524/problem-accessing-solidity-getter-using-ethers-js

submitted by /u/Taking-Jester766
[link] [comments]
Get BONUS $200 for FREE!

You can get bonuses upto $100 FREE BONUS when you:
πŸ’° Install these recommended apps:
πŸ’² SocialGood - 100% Crypto Back on Everyday Shopping
πŸ’² xPortal - The DeFi For The Next Billion
πŸ’² CryptoTab Browser - Lightweight, fast, and ready to mine!
πŸ’° Register on these recommended exchanges:
🟑 Binance🟑 Bitfinex🟑 Bitmart🟑 Bittrex🟑 Bitget
🟑 CoinEx🟑 Crypto.com🟑 Gate.io🟑 Huobi🟑 Kucoin.



Comments