How I Created An Ethereum Token For The Black Panther’s Kingdom

Screen Shot 2018-02-20 at 12.56.09 AM.png

Sooo I watched ‘Black Panther' this weekend, and I loved it...so much so that I spent the weekend pretending I lived in Wakanda. And why not? Who says you have to stop daydreaming when you become an adult....Why was my pretend life better than my real life though? Lawl! We’re not here to discuss my real life....
Screen Shot 2018-02-19 at 8.59.42 PM.png

Anyways, in my incredible life in Wakanda, I receive a secret summons to the the high court, full with an ozone ripping spaceship ride. This was the ride of my life that concluded with me getting commissioned by King T’challa to create the great kingdom’s crypto token!
King T’challa and I agreed that PantherPower best captured the essence of his spectacular kingdom. After much research alongside, Shuri, I created Wakanda’s new vibranium backed token. Below is my documentation of my lesson learning how to craft the PantherPower token.
Screen Shot 2018-02-19 at 5.04.19 PM.png

It all began with an honorable judge of the high court, @fodediop, explaining what I would need for this mission..

  1. Chrome web browser
  2. An editor like Atom, Sublime, Vscode etc.
  3. Some familiarity with the command line (you can just use mac’s terminal or an equivalent)
  4. Node js 8

Metamask:

I googled Metamask and clicked on ‘Get Chrome Extension'. The reason I needed Metamask was because it basically runs public ethereal nodes thru Infura, which takes out the work you’d have to do otherwise. Metamask enables Google Chrome the ability to become an Ethereum browser. This would give me the superpower of gettin data from the blockchain. Once you have Metamask, you can then make Ethereum transactions through your Chrome Browser.

I can make ethereum transactions and get data from the blockchain through my Chrome browser??
giphy.gif

The Second step I took was to install truffle

$ npm install -g truffle

Step 2. I created a directory for our new coin, CD’d into it, and initialized my project.

$ mkdir pantherPower
$ cd pantherPower
$ truffle init

Truffle on deck, let's go!

Now this next part is creating the actual pantherPower(If you're following along, name your coin whatever you wish)

I began by installing OpenZeppelin framework. (sidebar- why does OpenZepplin always make me think of ..Led Zeppelin?)
OpenZepplin is an awesome framework that contains a bunch of ready built contracts including the ERC20 token contracts that we'll want to deploy.

(You’ll have to Just keep pressing return to use the defaults)

package name: (panther-power)
version: (1.0.0)
description:
entry point: (truffle.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /Users/masonf/src/panther-power/package.json:

{
  "name": panther-power,
  "version": "1.0.0",
  "description": "",
  "main": "truffle.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this ok? (yes) yes
$ npm install zeppelin-solidity

We can now create our token contract..go ahead and open contracts/PantherPower.sol ( whatever you've named your token) and add this:

import "zeppelin-solidity/contracts/token/StandardToken.sol";

contract PantherPower is StandardToken {
  string public name = PantherPower; 
  string public symbol = "Panther";
  uint public decimals = 2;
  uint public INITIAL_SUPPLY = 10000 * (10 ** decimals);

  function PantherPower() public {
    totalSupply = INITIAL_SUPPLY;
    balances[msg.sender] = INITIAL_SUPPLY;
  }
}

If you're wondering why we're using OpenZepplin's standard ERC20 token, it's because it’s tested, reliable software, highly recommended, and would be easier for the purpose of learning. I wanted to deploy a token without getting into the nitty gritty of creating one from scratch the first time around. I’ll write a post on creating one from scratch further down the road, as I learn more.

Moving forward, run truffle compile to verify that our contract compiles

Compiling ./contracts/PantherPower.sol...
Compiling zeppelin-solidity/contracts/math/SafeMath.sol...
Compiling zeppelin-solidity/contracts/ownership/Ownable.sol...
Compiling zeppelin-solidity/contracts/token/BasicToken.sol...

It will continue compiling for a couple seconds.

Now that that big boy is in motion, we’ll add what’s called a truffle Migration.

Create migrations/2_deploy_pantherpower.js and add:

var PantherPower = artifacts.require("./PantherPower.sol");
module.exports = function(deployer) {
deployer.deploy(PantherPower);
};

Once this was done, I configured truffle so I could deploy, using Using the Infura public nodes.

If we’re going to deploy to a public node we’ll need the private keys to our wallet. We don’t want to include the keys in our source code because if anyone with malicious intent somehow accesses our code, they could easily steal all our PantherPower ..and that would make us all very sad. :( So, to block a potential attack, we have a node module we'll install called dotenv.

Let’s keep going and install the modules so we can deploy to Infura.

npm install —save-dev dotenv truffle-wallet-provider ethereumjs-wallet

Go ahead and edit the following in your truffle.js

require('dotenv').config();
const Web3 = require("web3");
const web3 = new Web3();
const WalletProvider = require("truffle-wallet-provider");
const Wallet = require('ethereumjs-wallet');

var mainNetPrivateKey = new Buffer(process.env["MAINNET_PRIVATE_KEY"], "hex")
var mainNetWallet = Wallet.fromPrivateKey(mainNetPrivateKey);
var mainNetProvider = new WalletProvider(mainNetWallet, "https://mainnet.infura.io/");

var ropstenPrivateKey = new Buffer(process.env["ROPSTEN_PRIVATE_KEY"], "hex")
var ropstenWallet = Wallet.fromPrivateKey(ropstenPrivateKey);
var ropstenProvider = new WalletProvider(ropstenWallet, "https://ropsten.infura.io/");


module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
    ropsten: {
      provider: ropstenProvider,
      // You can get the current gasLimit by running
      // truffle deploy --network rinkeby
      // truffle(rinkeby)> web3.eth.getBlock("pending", (error, result) =>
      //   console.log(result.gasLimit))
      gas: 4600000,
      gasPrice: web3.toWei("20", "gwei"),
      network_id: "3",
    },
    mainnet: {
      provider: mainNetProvider,
      gas: 4600000,
      gasPrice: web3.toWei("20", "gwei"),
      network_id: "1",
    }
  }
};

Now, we’ll retrieve our private keys from MetaMask

Open up your .env

  1. Click on the orange fox icon that’s up on the top right of your Chrome browser window.
  2. On the right of "Account 1”, click on the ellipses
  3. Hit the "Export Private Key"
  4. Now confirm what your password is
  5. Finally you’ll want to copy your private key to your clipboard.

Paste your private keys in your ".env" file :

ROPSTEN_PRIVATE_KEY=“345YourPrivateKeyHere"
MAINNET_PRIVATE_KEY=“345YourPrivateKeyHere"

Your private keys should be exactly the same on both Ropsten and Mainnet:

You can use the ethereum test networks to test your contracts. There are several options you have out there like Ropsten, Rinkeby and Kovan. There may be others I’m not yet aware of. Ropsten was recommended to me by @fodediop, because it’s the least challenging to get Ropsten ETH . Go to to Metamask to get your test ETH : https://faucet.metamask.io/. Once you have ‘em you can finally deploy your own monaay ! Woohoo!

$ truffle deploy --network ropsten

You'll see a line called ‘Saving artifacts’ which is the new address of your contract. Copy and paste

Welcome to Wakanda my friends, you’re now ready for the big leagues....
Screen Shot 2018-02-19 at 5.05.36 PM.png
Go forth and share your newly minted tokens. You can share them on any ERC20 compatible wallets like myEtherWallet or Mist. #Wakandaforever

H2
H3
H4
3 columns
2 columns
1 column
16 Comments
Ecency