5. Create smart contract
A step-by-step guide showing how to add a smart contract to the Porta blockchain
We start by creating a new flipper smart contract but please be advised, this is only for example purposes. We assume at this point you will have built your own smart contract and be ready to upload that to the Porta blockchain.
Create a new smart contract
cargo contract new flipper
The above command created a new project folder named flipper. Enter that folder now:
Test the contract to confirm everything is working as expected
cargo +nightly test
Build the contract
cargo +nightly contract build
If you receive an error about wasm-opt version, please refer to the link below to solve it.
If you did not receive an error, or you did but fixed it using the above link, you are now able to proceed.
The command (cargo +nightly contract build) will build for the ink! Project:
- a Wasm binary
- a metadata file (which contains the contract's ABI)
- a .contract file which bundles both.
If all goes well, you should see a target folder which contains these files:
Ensure you are on Developer > Contracts
Click: Upload & deploy code
Click and drag the flipper.contract file onto the input field
The screen will now show this
- The constructor to initialise the contract and any attributable settings
- The amount of funds to give to the token (known as the endowment). Ensure the endowment amount is over 100 tokens (because 100 tokens is the minimum number of token allowed for an account to exist on the Porta blockchain).
- The maximum gas fee the contract should use.
Congratulations. Your smart contract is deployed on the blockchain and you are now part of a growing community.
You can now move onto step 6: Interact with your smart contract on the Porta blockchain.