Flextesa TORU Sandbox
Flextesa now includes a Transaction Optimistic Rollups sandbox.
In anticipation of the Smart Contract Optimistic Rollup, this first step offers a sandbox for familiarizing oneself with the Transaction Optimistic Rollup, commonly referred to as TORU. This initial implementation of rollups on Tezos was included with the Jakarta protocol upgrade. See the TORU documentation here. This article will demonstrate how to run a Flextesa sandbox network with a TORU and TORU node operating on it. Additionally, we will introduce a few commands for getting started with the TORU.
The examples below will illustrate running the sandbox network with Docker. The implementation can be found in this script, which is a call to flextesa mini-network --tx-rollup [LEVEL:NAME]
( find its documentation here).
Starting the TORU Sandbox
Start the Flextesa mini-network with the following command:
$ image=oxheadalpha/flextesa:latest
$ script=limabox
$ docker run --rm --name my-sandbox -p 20000:20000 --detach \
"$image" "$script" start_toru
Current information on the latest Docker image and available scripts is available in the Flextesa documentation.
The start_toru
command will start the sandbox. At blocklevel 10 a TORU named torubox
will be originated and a TORU node will start. With 5 second block times, the TORU origination operation will be included after approximately one minute.
Before you can interact with the TORU sandbox, you will need to retrieve information about the TORU node and a smart contract which can be used for depositing tickets into a TORU account. You can do this with the toru_info
command.
$ docker exec my-sandbox ${script} toru_info
{
"toru_node_config": {
"rollup_id": "txr1arPn95HNJ2JPxFL1q51LGgk4KeR4v36p8",
"rpc_addr": "0.0.0.0:20002",
"mode": "operator",
"signers": {
"operator": "tz1db9qaMMNoQPAATe2D3kafKzWWNuMhnmbT",
"submit_batch": "tz1YVgxuvoqc2DxLjMcmgcpgnWXn6wiJNf5E",
"finalize_commitment": "tz1WbzTV5WrHBbfbc8Bw55xaQWLjNvfcBKp4",
"remove_commitment": "tz1ihyGvQHQu1F6TVMqKJdPtw2BHqMcDotsT",
"rejection": "tz1gDMHL96KSohLp2H5RPFxAM7wATD7zffRV",
"dispatch_withdrawals": "tz1LuLiAjZs2sFgivjsuLiuB8nJA48pVfcQc"
},
"allow_deposit": true
},
"turo_ticket_deposit_contract": {
"name": "torubox-deposit-contract",
"value": "KT1NjJEFRjAugzPwAkEccTAq3v2SYoScyGnL"
}
For the next few examples we will record the rollup_id
, rpc_addr
(port number only) and value
(the KT1
address for the torubox-deposit-contract
).
$ rollup_id=txr1arPn95HNJ2JPxFL1q51LGgk4KeR4v36p8
$ rpc_port=20002
$ contract=KT1NjJEFRjAugzPwAkEccTAq3v2SYoScyGnL
An octez-client
and tx-rollup-client
have been configured inside of the sandbox. It will be helpful to set up an alias for both. The TORU client will use the -E | --endpoint
option to point to the RPC address of the TORU node.
$ alias tcli="docker exec my-sandbox octez-client"
$ alias torucli="docker exec my-sandbox octez-tx-rollup-client-PtKathma -E http://localhost:${rpc_port}"
Sending Tickets to a Rollup Address
TORU addresses begin with tz4
. You will need to create one in order to receive tickets. Use the following commands.
$ tcli bls gen keys rollup_bob
It is important to save this mnemonic in a secure place:
hamster real drill flip turtle orphan flush slam leg pupil useless solid
abandon hard car liberty million tennis pelican say erosion biology trumpet
under
The mnemonic can be used to recover your spending key.
$ tcli bls show address rollup_bob
Hash: tz4EimhLzauGZjt6ebLDzbD9Dfuk9vwj7HUz
Public Key: BLpk1x8Eu1D5DWnop7osZtDx8kkBgG83tFiNcyBKkFatUg1wKpVbmjY2QqJehfju1t7YydXidXhF
To transfer tickets to rollup_bob
you will make a call to the default entrypoint of the torubox-deposit-contract
from a layer-1 address. As with most of the Docker scripts in Flextesa the Alice and Bob accounts will be included by default.
$ bobs_tz4=tz4EimhLzauGZjt6ebLDzbD9Dfuk9vwj7HUz
$ tcli transfer 0 from alice to "$contract" \
--arg "(Pair \"my_tickets\" 100 \"${bobs_tz4}\" \"${rollup_id}\")" \
--burn-cap 1
This sequence of operations was run:
Manager signed operations:
From: tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb
Fee to the baker: ꜩ0.00087
Expected counter: 1
Gas limit: 5056
Storage limit: 87 bytes
Balance updates:
tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb ... -ꜩ0.00087
payload fees(the block proposer) ....... +ꜩ0.00087
Transaction:
Amount: ꜩ0
From: tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb
To: KT1ULYjCwdCsYT58aaBnNeTzBhRPgWjJ2YGa
Parameter: (Pair "my_tickets"
100
"tz4WiSFpMbbTWLjFzgw9BGyLr34EHLqJ8NDj"
"txr1XyYBwQVAQ5gpD2M2Mpu2v4PoMiyRykgms")
This transaction was successfully applied
Updated storage: Unit
Storage size: 132 bytes
Paid storage size diff: 67 bytes
Consumed gas: 2860.011
Balance updates:
tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb ... -ꜩ0.01675
storage fees ........................... +ꜩ0.01675
Internal operations:
Internal Transaction:
Amount: ꜩ0
From: KT1ULYjCwdCsYT58aaBnNeTzBhRPgWjJ2YGa
To: txr1XyYBwQVAQ5gpD2M2Mpu2v4PoMiyRykgms
Entrypoint: deposit
Parameter: { Pair (Pair 0x01d8b1f9eada54039ed64db960ce25accda16a95cc00 (Pair "my_tickets" 100))
0xee249a980a49e946b8ff2ba25beb45dcef30f0e1 ;
string }
This transaction was successfully applied
Consumed gas: 2095.046
Ticket hash: exprtp67k3xjvBWX4jBV4skJFNDYVp4XKJKujG5vs7SvkF9h9FSxtP`
This call sends 100
tickets containing a string "my_tickets"
to rollup_bob's tz4
address at the TORU's txr1
address. There is no business logic in this contract. It will work to transfer 0 Tez to the contract when calling it from alice
.
Now record the ticket hash and use the TORU client to check the balance of rollup_bob.
$ ticket_hash=exprtp67k3xjvBWX4jBV4skJFNDYVp4XKJKujG5vs7SvkF9h9FSxtP
$ torucli get balance for rollup_bob of "$ticket_hash"
100
This covers the basics of starting a Flextesa sandbox with a TORU. We have also demonstrated creating a TORU wallet and transferring tickets to it. You will find more examples of transaction optimistic rollups and related commands in the Tezos documentation here.
For more information on Flextesa, please visit the repository.