How To Launch Your Own Crowdsalable Cryptocurrency

4 min read Adam Bavosa on Feb 14, 2018
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

How to deploy a cryptocurrency with crowd sale capability to the Ethereum network. Web3.js development and end-to-end testing is demonstrated with the Truffle Suite.

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

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 PubNub 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__'

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

const xhr = require('xhr');
const basicAuth = require('codec/auth');
const username = '__YOUR_CLICKSEND_USER_NAME__';
const authKey = '__YOUR_CLICKSEND_AUTH_KEY__';
const uri = '';
const authorization = basicAuth.basic(username, authKey);

The PubNub 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.


After you have deployed your PubNub 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.

More from PubNub

NPP and HIPAA: Notice of Privacy Practices Definition
Healthcare CategoryJan 6, 20235 min read

NPP and HIPAA: Notice of Privacy Practices Definition

A Notice of Privacy Practices (NPP) is one of the requirements of HIPAA and helps patients understand their personal data rights.

Michael Carroll

Michael Carroll

HIPAA Violation Examples
Healthcare CategoryJan 5, 20236 min read

HIPAA Violation Examples

HIPAA violations can be financially expensive and devastating to a brand. Examine some examples of HIPAA violations, and learn...

Michael Carroll

Michael Carroll

HIPAA Technical Safeguards: How To Protect Sensitive Data
Healthcare CategoryJan 5, 20236 min read

HIPAA Technical Safeguards: How To Protect Sensitive Data

HIPAA covered entities must follow the five technical safeguards to achieve HIPAA compliance and prevent data corruption.

Michael Carroll

Michael Carroll