Build

How To Launch Your Own Crowdsalable Cryptocurrency

4 min read Adam Bavosa on Feb 14, 2018

The trend for successful cryptocurrency founders is to first demonstrate an idea that solves a notable problem – write a white-paper explaining the solution involving the coin – and finally sell the coin to the masses.

The token contract from part I of this guide, Developing the ERC-20 Token, is exciting to see for ICO developers, but it isn’t able to do the newsworthy crowdsale out of the box. Let’s make that happen.


This is Part Three of our three-part series on How To Launch Your Own Production-ready Cryptocurrency. The other parts are:


Now that you have installed Truffle, used the CLI, explored Solidity, and written some test code, we can unbox an existing Truffle project – Crowdsalable Ethereum Token. Let’s make a new directory and pull this project directly from my Github repo using the Truffle CLI.

mkdir crowdsalable-eth-token && cd crowdsalable-eth-token
truffle unbox git@github.com:ajb413/crowdsalable-eth-token.git

This Truffle project has a more robust implementation of an Ethereum token. The token name and symbol can be changed by the owner after the contract is already deployed. The owner can also configure and open new crowdsales at any time.

The truffle box comes with a development mode UI for executing contracts on the local Ethereum client. The UI uses the 10 static wallets that the truffle develop command initializes on your machine – to execute transfers, view wallet balances, and launch the exciting crowdsale.

Broadcast Crowdsale Announcements

The app/ folder contains the web UI and also an extra bit of PubNub magic. When a crowdsale is launched, the owner has the option to text message all of their followers with the crowdsale details, so they can begin purchasing your token.

This functionality is powered by the ClickSend API and Functions. In order to enable this real-time updating feature, you must sign up for PubNub and ClickSend. You insert your api key, publish key, and subscribe key where noted in app.js and sms-handler.js. Also edit the JavaScript array of Phone Numbers to choose who receives an SMS.

excerpt from app/js/app.js

var pubnub = new PubNub({
  publishKey : '__YOUR_PUBNUB_PUBLISH_KEY__',
  subscribeKey : '__YOUR_PUBNUB_SUBSCRIBE_KEY__'
});
var pubnubSMSChannel = '__YOUR_FUNCTION_LISTENING_CHANNEL__';

excerpt from app/pubnub-functions/sms-handler.js – Deploy this to Functions!

const xhr = require('xhr');
const basicAuth = require('codec/auth');
const username = '__YOUR_CLICKSEND_USER_NAME__';
const authKey = '__YOUR_CLICKSEND_AUTH_KEY__';
const uri = 'https://rest.clicksend.com/v3/sms/send';
const authorization = basicAuth.basic(username, authKey);

The Function event handler must be deployed in the PubNub Admin Dashboard. See this tutorial for deploying function event handler code in 2 minutes.

A Development UI with Web3.js

Next we run the local Ethereum client the same way we did earlier.

cd crowdsalable-eth-token
npm i
truffle develop
## Truffle development blockchain and console are booted
truffle(develop)> compile
truffle(develop)> migrate
truffle(develop)> test
  • Leave the truffle console running
  • Open a new command line window
  • Navigate to the same project directory
  • Run the development UI with:
npm run dev
> crowdsalable-eth-token dev /crowdsalable-eth-token
> webpack-dev-server
Project is running at http://localhost:8080/

Next, open the UI in your browser and explore the key features. We can:

  • Launch a new crowdsale
  • Transfer token from wallet to wallet
  • Purchase token from a crowdsale using ETH
  • Check the balance of any wallet

The nature of the development environment allows anyone to invoke functions like createCrowdsale and transfer, when in reality, these methods cannot be invoked by just anyone. For onlyOwner decorated Solidity functions, the invoker must be the owner of the contract and must sign their requests with their private key (see rawTransaction function in test/integration.test.js). Also functions like transfer will only be able to send token from the wallet that the private key belongs to. This will be more restrictive on the main network for the right reasons.

web3.eth.sendRawTransaction(...)

After you have deployed your Function, you are able to launch a crowdsale and send a mass SMS to all of your followers when the contract opens. Input a name, click the Launch button, and check your phone!

Token Develop UI

The configuration of the crowdsale is specified in the app/js/app.js script in the launchCrowdsale event handler. By default, the crowdsale is open forever, starts with 100,000 TOK to sell, and a buyer receives 3 TOK per ETH that they pay.

Use the default wallet public keys listed at the bottom of the UI for transfers, purchases, and balance checks. Remember, on this network, the wallets each have 100 fake ETH to play with.

Once you are ready to deploy, read over the guide in part II of the trilogy if you haven’t already. For live demonstrations of blockchain programming, check out our events and Meetup page.

0