Deploy a solidity smart contract in Parastate
How to deploy a simple DApp in ParaState.
This is a tutorial on how to deploy a simple Dapp on the ParaState substate blockchain.
As the Substrate (and Polkadot) gains popularity, there is increasing demand for running Ethereum smart contracts and Dapps on Substrate-based blockchains.
The ParaState (and Second State) team develops software that enables Ethereum smart contracts on Substrate blockchains. It supports smart contracts written in Solidity and other WebAssembly-compatible languages and supports both polkadot.js and web3.js based web application front-ends.
For the full article on the subject please refer to: Running Ethereum smart contracts in a Substrate blockchain.
This tutorial will not go in detail on how to write a smart contract nor the syntax of Solidity.
Please refer to the documentation in order to learn more about the subject.
We will use BUIDL online IDE.
BUIDL
Buidl is an online ide which allows to:
1. Write a smart contract in solidity
2. Compile it
3. Deploy the contract on a chain
It also allows to create more complex Dapps including HTML and JSS.
For more info refer to the BUIDL home page and the github repo.
Let’s go through each step:
1. Add the ParaState Chain in Metamask
In order to operate with the testnet we will need some test token.
We can easely connect Metamask to the ParaState testnet following this guide: https://medium.com/ethereum-on-steroids/using-metamask-to-access-parastates-testnet-b65bc17a5f78
2. Ask for tokens from the faucet
Follow this Link to access the faucet. Copy the address from Metamask
and ask for tokens.
In this way you will have State tokens in Metamask(Those are just test tokens!)
3. Open BUIDL
Please load buidl in your browser following this link:
https://buidl.secondstate.io/
You should see this environment with the Simple Storage Contract
4. Connect ParaState to BUIDL
In order to deploy a smart contract on the ParaState chain we need to connect BUIDL to the correct endpoint.
To do so:
1. Click on the providers button:
It will show a window like this:
2. Select Customize and add:
- endpoint: https://rpc.parastate.io:8545/
- chain id : 123
- gas: 1
- gas limit: 8000000
If everything works you will see the green status accessible and the height of the chain
5. Send tokens to your BUIDL account
In order to deploy a contract BUILD we would need tokens in BUIDL.
We will use the same account we sent State to from the faucet
- Click on account:
- Go to Metamask and click on Account details (from the same account you used to get tokens from the faucet)and export the private key.
- Copy the key
- Go in import account in Buidl and paste the private key
You should have:
5. Write a contract
Now that we have tokens on our account is time to write the contract.Here i will just take the Auction example from the solidity documentation.
From the Dapp tab we can also load / write HTML, CSS and add more resources to have a sophisticated UI.
6. Compile the Smart Contract
Choose the version of Solidity compiler you would like to use (In this example the 0.4.2.6):
Click on the compile button as shown in the screenshot below:
If the compiler did not find errors in the code on the left side of BuILD we should find the compiled version of our contract ready to be deployed.
7. Deploy the contract
In order to deploy the contract we just need to click on the deploy button.
Note that in my case the contract requires also 3 input parameters:
_biddingTime
_reveal_Time
_beneficiary (Address)
So i provided the three parameters as shown below:
Click on Deploy to chain
And after a short time the transaction is confirmed.
The pic above shows how a deployed contract look like.
The transaction status is : Success.
On the left side we can interact with the contract and calling the functions.
As example i called:
1. Beneficiary and showed my address
2. End and terminated the auction
This is how is is to deploy a Dapp on the substate chains thanks to software developed by the the ParaState (and Second State) team.
Please experiment with it, compile and deploy more complex Dapps and share with the community.