Flextesa: the Swiss army knife of development on Tezos
Learn more about Flextesa, a sandboxed local Tezos blockchain that you can use to develop smart contracts and dapps
Blockchains are not the easiest environments to build applications: every blockchain has its own features that must be taken into account, they sometimes use specific programming languages for their smart contracts, you can’t use the mainnet to test your applications because the transactions incur a fee, etc.
Ideally, in the first steps of creating your application, you would like to have a little blockchain of your own that runs on your computer and that you don’t mind messing up. You can send transactions to it, update smart contracts and if something goes wrong, you can just turn it off and on again.
This is what Flextesa does.
What is Flextesa?
Flextesa stands for Flexible Tezos Sandbox. It creates a mockup Tezos blockchain on your computer that you can interact with and use to test your applications. The real power of Flextesa is that it not only runs a little Tezos blockchain locally, but it also lets you fine-tune the parameters of the Tezos instance.
By default, Flextesa bakes a new block every 5 seconds, three times faster than the block time on mainnet, which allows a faster development process. However, you can also change this parameter and have Flextesa bake a new block every second, for example, making the process even faster.
Flextesa closely follows the upgrades on Tezos. For instance, it is possible to use Flextesa to run a smart rollup and interact with it since the Mumbai upgrade.
In addition to that, Flextesa is very easy to use. All you need to run it on your computer is Docker Desktop. You can pull the container from Docker Hub and start using it right away!
How to use Flextesa
The easiest way to use Flextesa is to use its Docker image.
Open a new terminal window and type:
image=oxheadalpha/flextesa:latest
script=nairobibox
$ docker run --rm --name my-sandbox --detach -p 20000:20000 \
"$image" "$script" start
The image is the latest version of Flextesa available on Docker Hub, while the script indicates the name of the protocol you want to run Flextesa with.
The script will install (if it wasn’t installed before) and run the Nairobibox for Flextesa and you will be able to interact with its RPC from this address: http:\\localhost:20000
.
When you launch Flextesa, 2 accounts will be available: Alice (with the address tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb
) and Bob (with the address tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6
). These accounts are fully funded and you can use them to make transactions. You can get the private keys of these accounts by entering this command:
$ docker exec my-sandbox nairobibox info
Tweaking the parameters
It is possible to pass parameters to the Docker command in order to change the behaviour of the Flextesa box.
The most basic change you can make is about the block time: by default, the box will bake a new block every 5 seconds, but if you need a different block time, here is how you can do it:
$ docker run --rm --name my-sandbox --detach -p 20000:20000 \
-e block_time=1 \
oxheadalpha/flextesa:latest \
nairobi start
Flextesa will launch the Nairobi box with a block time of 1 second, i.e. a new block will be baked every second.
You can also have Flextesa bake blocks on demand! Type the following command:
$ docker run --rm --name my-sandbox --detach -p 20000:20000 \
oxheadalpha/flextesa:latest \
nairobi start_manual
From this moment, you will have to interact with Flextesa when you will want to create a new block with the following command:
$ docker exec my-sandbox nairobibox bake
Another parameter may be interesting to tweak if you are developing a dapp and want to test it against Flextesa before testing it on Ghostnet. By default, the CORS origin policy of Flextesa is closed, so every request you send from a browser to Flextesa will fail.
However, it is possible to open it with the following parameter:
-e flextesa_node_cors_origin="*"
After that, you can use, for example, Taquito, to interact with the smart contracts originated inside the Flextesa instance.
Smart rollups
You can also use Flextesa to run and test one of the latest additions to the Tezos blockchain: smart rollups!
Using the tx-kernel
, users can run the smart rollup sandbox, initiate the tx-client
, and manage ticket transactions through the mint_and_deposit_to_rollup
contract.
It is also possible to launch a smart rollup that runs a custom kernel you provide:
$ docker run --rm --detach --volume /path/to/kernel/files:/rollup \
--name my-custom-kernel oxheadalpha/flextesa:latest nairobibox \
start_custom_smart_rollup $KIND $TYPE /rollup/kernel.wasm
This command starts a container named my-custom-kernel
. The volume
option mounts the /rollup/files
directory to the container at /rollup
. Replace $KIND
and $TYPE
with the values appropriate for your kernel. /rollup/my-kernel.wasm
is the location of your kernel within the container.
After that, you can use the smart_rollup_info
command to output the smart rollup node’s configuration file, which includes the sr1
address for the smart rollup:
$ docker exec my-sandbox mumbaibox smart_rollup_info
{
"smart_rollup_node_config": {
"smart-rollup-address": "sr1KVTPm3NLuetrrPLGYnQrzMpoSmXFsNXwp",
"smart-rollup-node-operator": {
"publish": "tz1SEQPRfF2JKz7XFF3rN2smFkmeAmws51nQ",
"add_messages": "tz1SEQPRfF2JKz7XFF3rN2smFkmeAmws51nQ",
"cement": "tz1SEQPRfF2JKz7XFF3rN2smFkmeAmws51nQ",
"refute": "tz1SEQPRfF2JKz7XFF3rN2smFkmeAmws51nQ"
},
"rpc-addr": "0.0.0.0",
"rpc-port": 20010,
"fee-parameters": {},
"mode": "operator"
},
}
Once it’s done, you can interact with the smart rollup. For more detailed information, you can read this article.
Conclusion
The blockchain development environment can be intricate, with each platform possessing its unique quirks and requirements.
Flextesa addresses this challenge for Tezos developers by providing a flexible, local sandbox environment. This mockup Tezos blockchain is not only versatile in its operational parameters, allowing developers to emulate various real-world conditions, but it is also user-friendly and easily accessible via Docker Desktop.
Furthermore, this tool has kept pace with Tezos’ innovations, including the integration of smart rollups. Flextesa thereby empowers developers with a safe, cost-effective space to test, experiment, and refine their blockchain applications, reducing the hurdles of the development process and paving the way for smoother transitions to the mainnet.
Flextesa is an indispensable tool for any developer who wants to build on Tezos.