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.cd
into it. Initialize your Web3 Actions by running the tenderly actions
init
command:tenderly actions init --language javascript
.package.json
holds npm dependencies which will be available when you deploy your Web3 Action. The tsconfig.json
file holds Typescript configuration related only to .ts
files within the actions
directory.tdly-actions
directory.files/artifacts/TicTacToe.json
, copy/paste the file contents and paste them into your projectโs TicTacToe.json
file.actions
directory (e.g. TicTacToe.json
).TicTacToe.json
file as a module and access it as an object.tsconfig.json
file and include the following two configurations under the compilerOptions
entry:players
object.GameCreated
event that is defined in the smart contract.newGame
function, so weโre interested in the first log entry. We can get the result
with ethers.js by decoding txEvent.logs[0].data
of the GameCreated event, based on the TicTacToe.abi
.result.gameId
. We want to track the data for this particular game: players and moves they made, using a brand new Game
instance. Weโre saving the object representing the new game in the Storage with this command: context.storage.putJson(gameId, game)
.specs
section, 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.trigger
that Tenderly is supposed to watch out for to invoke the action. This is a transaction
trigger that will run when the block is mined. Weโre doing this for network 3
when the event NewGame
is emitted from the contract on the specified address.TTT_CONTRACT_ADDRESS
with 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.YOUR_USERNAME
and YOUR_PROJECT_SLUG
with your Tenderly username and the slug of your project. You can copy those from the Dashboard URL: https://dashboard.tenderly.co/{YOUR_USERNAME}/{YOUR_PROJECT_SLUG}/transactions
deploy
command 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.ts
file also contains the code that allows us to:storage.getJson
).game.players[player] = playerNumber
storage.putJson
.specs
from the tenderly.yaml
file to include the specifications needed to invoke the Web3 Action.deploy
command. This command will also redeploy previously deployed Web3 Actions.newGame
input field. To submit the transaction, click the joinGame
button:playerNumber: 1
.joinGame
again. Upon the completion of the transaction, youโll see a similar log output in the Execution History.result.boardRow
and column result.boardCol
with the playerโs input game.players[player]
.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.GameOver
event. The GameOver
event is fired when a player makes a move that wins the game or when the board is full. This event is fired after the PlayerMadeMove
event. In the txEvent.logs
list, the GameOver
event is the second element.GameOver
event is to access it via the txEvent.logs[1]
. However, weโll implement a more robust solution which doesnโt depend on the order and number of events fired.gameOverTopic
using 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 GameOver
event log that we can decode using Ethers.GameOver
action by extending the specs
in tenderly.yaml
: