visit
The Ethereum mainnet itself is a victim of its own popularity and success. It is often congested resulting in high transaction fees and slow confirmation time. It sometimes costs over $50 per smart contract function call, and requires minutes or hours before the function call result is finalized.In this tutorial, we will create an Ethereum-compatible social media Dapp on the . The Oasis blockchain was started by well-known computer security researchers at the University of California at Berkeley. It aims to build a privacy-first blockchain, where the on-chain data could be private and confidential, while all the nodes can remain decentralized and untrusted. After 2 years of development, the team has built a public blockchain that is very fast and scalable while preserving privacy. For developers, we can deploy Ethereum applications on Oasis network through the nodes.
The term ParaTime refers to a Parallel Runtime. The design of the Oasis blockchain allows each node to run its own runtime software and to provide services to the public. The Oasis Ethereum ParaTime is run by a set of Oasis nodes that opted to support the Ethereum protocol.The blockchain is currently free to use and confirms transactions in 6 seconds. For this tutorial, the Oasis foundation is also providing , which is Oasis's native cryptocurrency, to everyone who completes and publishes his or her Dapp.
Figure 1. Select the OasisTweet project.
Since this is the first time you start this IDE, it creates several new Ethereum account addresses for you to use. You will need to have some tokens in those accounts so that you can pay “gas” to deploy and use your smart contracts. Click on the Accounts tab on the IDE and copy the selected default address.
Figure 2. The auto-generated addresses.
Next, go to the OETH developer faucet below, and paste your address. It takes about 10 seconds for the OETH to be deposited into your account.Figure 3. Get a test OETH for your account address.
It also has an array called
comments
. It allows any user to leave a comment on your Dapp web page. However, it is important to notice the price field and the addComment()
function. The user must pay the price amount of OETH to YOU in order to leave a comment on your page!contract OasisTweet {
address owner;
string public message;
string public image;
uint256 public price;
struct Comment {
string name;
string comment;
bool isValue;
}
mapping (address => Comment) comments;
... ...
function OasisTweet (string _message, string _image, uint256 _price) public {
owner = msg.sender;
message = _message;
image = _image;
price = _price;
}
function addComment (string _name, string _comment) public payable {
require(msg.value >= price);
if (!comments[msg.sender].isValue) {
addrs.push(msg.sender);
}
comments[msg.sender] = Comment(_name, _comment, true);
}
}
Click on the Compile button and the IDE compiles the smart contract into Ethereum bytecode.
Figure 4. Compile the smart contract.
Before you deploy the contract to the blockchain, fill out your message, image URL, and price you demand of each comment. Those will be stored on the blockchain with the contract.Figure 5. Populate your message, image URL, and price before deploying the contract.
Then click on the Deploy on the chain button to deploy the smart contract to the Oasis Ethereum ParaTime blockchain. It will take about 10 seconds to confirm the contract by Oasis blockchain validators. You will see a success message in the log panel. If you encounter an error at this point, make sure that your default account has an OETH balance!
Figure 6. Successful deployment of the contract. You must have OETH in your default address.
Figure 7. The web app has HTML and JS sections.
The
reload()
function in the JavaScript loads data from the blockchain contract, and populates them on the HTML page. Pay attention to the instance.addComment()
function. It takes a user comment from the web form, and sends it to the contract in a transaction. In the transaction, the user pays price OETH to the contract in addition to gas fees to the network.var contract = web3.ss.contract(abi);
instance = contract.at(cAddr);
instance.message(function (e, r) {
$("#message").html(r);
});
instance.image(function (e, r) {
$("#image").prop("src", r);
});
instance.price(function (e, r) {
price = r;
$("#pricealert").html("Requires " + price + " wei to comment");
});
instance.addComment ($("#name").val(), $("#comment").val(), {
value: price,
gas: 499000,
gasPrice: 1
}
Click on the Run button on the IDE to run the web app. You will see the web page in the right panel of the IDE. You can now interact with it by paying and leaving a comment.
Figure 8. Run the Dapp web UI in the IDE.
Finally, you are ready to publish your Dapp! You can take the HTML and JS content and put them on any static web page host. Or, you can click on the Publish button on the IDE.
Figure 9. Publish the Dapp web page.
The published web page is . For users who want to leave a comment, they will need a connected to , or fund in their default address on the web page.Figure 10. The Dapp web page is accessible to all. But commenters need to pay OETHs.