Get familiar with Tezos key operations, including creating, testing, compiling, deploying, and interacting with smart contracts.
In this article, we show up how to create a simple decentralized application,deploy it and interact with the smart contract on Tezos blockchain.
Creating a Contract:
we are going to write our contract using the online editor for the sake of simplicity, https://smartpy.io/ide/, our smart contract will be developed on python then compiled to Michelson that can then be deployed at an address on Tezos blockchain, where its functionalities can be invoked.We start by defining entry point that refers selected method to interact with external calls.
We give an example of Alice for instance trying to send a deposit to Bob, allowing Bob to withdraw it.
The deposit operation will take the amount sent to the transaction, if the amount is 0, it should fail as shown in the code comments below.The transaction is valid only if the deposit is valid and the sender is Alice in this example.
The Withdraw operation takes an argument that represent the amount of Tezies to withdraw, in this example the transaction is valid only if the sender is Bob and the amount is less or equal to the deposit sent by Alice as shown in the code below:
Testing the contract:
After the creation, we can proceed to test it part by part, always using the only editor we create an object of our already defined class and execute different scenarios as shown in the code below.
After that we can see our contract behavior online by pressing run on the simulator.
Compiling the contract:
Now we are on the latest stage of compilation and deployment. After running the code a Michelson code is generated which we will deploy as shown in figure below.
after that will lead you to a web page where you can set your node and network, I use carthagenet for test. Then follow instructions to set your private key and account by importing faucet from https://faucet.tzalpha.net/, then compute your private key, activate account, and finally reveale it on carthagenet. After deploying your contract you get your contract ID which a unique ID that you can use to interact or check your contract status.
Now that we are familiar with Tezos blockchain and how to create, compile and deploy Tezos smartPy smart contract, the next step will be to add some complexity to the contract in order to make it general and handle most of cases.
The code used is only for learning purpose not for production :) Good Luck.