How to make calls to a smart contract from a specific signer using ThirdWeb?

30 views Asked by At

The function to call is whoseTurnIsIt() but this function will only work when called from an address which have joined a game. With the following code, it looks like the caller of the view function is another address (signer) rather than the wallet that is connected because I get the error YouHaventJoinedAnyGame.

How can I make a contract call similar to ethers .connect(signer) method?

export default function Gameplay() {
  const [state, setState] = useState(0)
  const { contract } = useContract(address, abi)
  const { data } = useContractRead(contract, "airnodeRrp")

  /* --------------------- USE EFFECT --------------------- */

  useEffect(() => {
    whoseTurnIsIt
  }, [data])

  /* -------------- CONTRACT FUNCTION CALLS ------------- */

  async function whoseTurnIsIt(): Promise<void> {
    // This line does not work because the call is made from a signer which has not joined a game
    const result = await contract?.call("whoseTurnIsIt")

    // I need something like ethers' connect method: contract.connect(signer).functionToCall()
  }

  /* ----------------------- RETURN ----------------------- */
  return (
    <>
      <div>{data}</div>
    </>
  )
}
0

There are 0 answers