Tim McCallum

How to write, deploy and test a blockchain-based smart contract — in minutes, for free!

How to write, deploy and test a blockchain-based smart contract — in minutes, for free!

Let’s dive right in…

Step 1

If you don’t have it already, download the Google Chrome web browser. We will be using it exclusively.

Step 2

Go ahead and get the CyberMiles MetaMask plug-in; the link will take you to the official Google Chrome store.

Step 3

Visit CyberMiles’ testnet faucet to get your 1,000 free CyberMiles Tokens (CMT). Simply paste your account address into the “Account” field.

Note: To get your account, simply click on “Account 1” of the MetaMask plug-in (which you just installed). Within seconds, your MetaMask wallet will display 1,000 new CMT.

Step 4

Now open CyberMiles’ free online smart contract editor and paste in some raw code (click on “view raw” in the bottom right of your screen).

The code will auto-compile. If not, click the “Start to compile” button in the Compile tab of the free online code editor.

Step 5

Switch over to the Run tab (in between the Compile and Settings tabs).

Type a message on the right hand side of the red deploy button (over the text, which currently reads string _creationMessage), and don’t forget to use double quotes around the message that you are typing.

Once your message is typed in “with quotes,” click the red Deploy button.

Keep an eye out for the CyberMiles MetaMask pop-up because you will need to “Confirm” the transaction with a single mouse click. If you do not get the pop-up, look in the upper right side of your Chrome browser for the notification (1).

1 notification for you to click and accept

The pop-ups are pretty obvious, so you should not have any issues.

Step 6

Test the contract by clicking the red sayHello button, on the side of your screen.

Step 7

To check the output, click on the green tick in the box beneath your code. This will open up the latest transaction and allow you to view the logs.

You will see, once you scroll down inside the grey logging area, that the immutable data has been successfully recorded, specifically:

  • “HelloWorld” event has been triggered
  • The calling address was that of your account (ex. 0xEBfC71f4ef3Eda82B65dE04B1cf1994f28C3B9CC)
  • The message is “Hello World”
  • The counter is now equal to 1

Step 8

Click the red “TerminateTheContract” button to remove the contract code and all of its storage (i.e. the counter and owner variables) from the blockchain. Keeping in mind that while the contract no longer exists on the network, the event logs are immutable and will remain indefinitely. Also, remember that all of your transactions, too, will be permanently displayed on the CyberMiles block explorer.

If you have any questions about the CyberMiles blockchain, feel free to leave a comment.

Please get in touch with us at CyberMiles if you would like more information about developing smart contracts.