Tezos smart contracts are compiled from a custom low level language called Michelson. For web developers however learning a new low level programming language is a barrier to entry… Enter LIGO and specifically ReasonLigo.
So this contract is storing a number and providing two functions to increase the number or decrease it.
Deploying A ReasonLIGO Contract
Let’s try deploying this contract to the babylon testnet using the LIGO playground IDE.
Open up this link and select ReasonLIGO from the list of options. This is a development playground where you can test, compile, deploy and evaluate smart contracts.
Select Deploy > Run and your smart contract will be deployed to the blockchain.
Next step is getting this working using your own credentials inside a dapp.
First job is to get some credentials and testnet tokens.
If that isn’t working just Google “Tezos testnet faucet”.
I’m going to be doing this in Node.js but you can also run it in a HTML page. See code further down for examples.
In this example we use an external library called ConseilJS to interact with a public Tezos node. We use this to initiate our test account using the credentials from the faucet and then deploy a very simple smart contract.
Full docs for ConseilJS are here: https://cryptonomic.github.io/ConseilJS/#/
Let’s compile the contract using the IDE. Select Compile and then tick the “Output Michelson as JSON” box, then click Run. Copy and paste the result into the script above between the backticks at “const contract = “;”
Now lets run the script:
In the output you should get an operation hash which can be entered on the block explorer here: https://better-call.dev/
Remember to change the network from mainnet to babylon testnet.
Next job is to invoke or use the smart contract.
Enter the contract address from the block explorer in the first line. This increments the stored number by 5. We need the tezosNode and keystore (generated from initaccount()) data a well from the previous code.
Each time we call the above code we are interacting with our smart contract. Any functions we have as part of the “main” entry point in ReasonLIGO can be called in this way.
ReasonLIGO A Beginners Guide
Here are some code snippets which should help with getting started developing smart contracts with ReasonLIGO