Injected Web3. Click “Deploy” once you’ve made sure that the account references the account in Metamask.
0x1EB...) and store it somewhere because we’ll need it for the steps that follow.
cdinto it. Initialize your Web3 Actions by running the
files/artifacts/TicTacToe.json, copy/paste the file contents and paste them into your project’s
TicTacToe.jsonfile as a module and access it as an object.
tsconfig.jsonfile and include the following two configurations under the
GameCreatedevent that is defined in the smart contract.
newGamefunction, so we’re interested in the first log entry. We can get the
resultwith ethers.js by decoding
txEvent.logs.dataof the GameCreated event, based on the
result.gameId. We want to track the data for this particular game: players and moves they made, using a brand new
Gameinstance. We’re saving the object representing the new game in the Storage with this command:
specssection, define the specs for
newGame(arbitrary name) to invoke the function
newGameAction. You can do so like this
newGameAction:newGameAction— first we define the name of the file containing the function and then the function name.
triggerthat Tenderly is supposed to watch out for to invoke the action. This is a
transactiontrigger that will run when the block is mined. We’re doing this for
network 3when the event
NewGameis emitted from the contract on the specified address.
TTT_CONTRACT_ADDRESSwith the actual address of your smart contract. If you want to deploy the contract to a network other than Ropsten, specify the network’s ID as the value of the network.
deploycommand using the Tenderly CLI:
newGame. Metamask should prompt you to confirm the execution of the Web3 Action.
0xb, which means it’s the 11th game started for this contract.
playerJoinAction.tsfile also contains the code that allows us to:
game.players[player] = playerNumber
tenderly.yamlfile to include the specifications needed to invoke the Web3 Action.
deploycommand. This command will also redeploy previously deployed Web3 Actions.
newGameinput field. To submit the transaction, click the
joinGameagain. Upon the completion of the transaction, you’ll see a similar log output in the Execution History.
result.boardColwith the player’s input
processNewGameState, will log the board to the console, but you can also send a tweet when a move is made, trigger a new transaction on the chain, or use it in any other way.
GameOverevent is fired when a player makes a move that wins the game or when the board is full. This event is fired after the
PlayerMadeMoveevent. In the
GameOverevent is the second element.
GameOverevent is to access it via the
txEvent.logs. However, we’ll implement a more robust solution which doesn’t depend on the order and number of events fired.
gameOverTopicusing ethers via
iface.getEventTopics. This will give you the corresponding hexadecimal value. Next, you need to find the log entry in the
txEvent.logs, whose topics list contains the
gameOverTopic. This is our
GameOverevent log that we can decode using Ethers.
GameOveraction by extending the