Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
183 lines (133 sloc) 4.61 KB

Emerald Starter Kit

Create A New Emerald DApp

Emerald SDK utilizes Truffle's smart contract management to compile, deploy, and test smart contracts. However, you don't need to install Truffle!

Make a directory for your DApp. Name the directory emerald-starter-kit.

$ mkdir emerald-starter-kit

Inside the DApp directory, create a new Emerald DApp with emerald new

$ cd emerald-starter-kit
$ emerald new
New Emerald project created

Internals

Looking at what is included in the starter-kit.

$ ls
config            package.json        truffle.js
contracts        public            tsconfig.json
migrations        src            tslint.json
node_modules        test            webpack.config.ts
package-lock.json    truffle-config.js

The starter kit is a barebones DApp which uses React. However, Emerald is attentive to specific file structures as Truffle would.

  • contracts/ : directory is for Solidity contracts.
    • Migrations.sol : is automatically generated by and often does not need to be touched.
    • Todos.sol : is the custom smart contract for the DApp.
  • migrations/ : directory for scriptable deployment files
    • text/ : directory for testing the DApp and contracts
  • truffle.js : blockchain client configuration file.

{% hint style="info" %} truffle.js is where the user's Ethereum Classic client in configured. {% endhint %}

truffle.js

{% code-tabs %} {% code-tabs-item title="truffle.js" %}

// Common Emerald Wallet "geth" config.
module.exports = {
    networks: {
      development: {
        host: 'localhost',
        port: *,
        gas: *,
        network_id: '*' // Match any network id
      }
    }
  };

{% endcode-tabs-item %}

{% code-tabs-item title="Emerald Wallet Client" %}

// Default with Emerald
module.exports = {
    networks: {
      development: {
        host: 'localhost',
        port: 8545,
        gas: 6000000,
        network_id: '*' // Match any network id
      }
    }
  };

{% endcode-tabs-item %}

{% code-tabs-item title="Ganache Client" %}

// Common Ganache Ethereum client config.
module.exports = {
    networks: {
      development: {
        host: 'localhost',
        port: 7545,
        gas: 6000000,
        network_id: 5777
      }
    }
  };

{% endcode-tabs-item %} {% endcode-tabs %}

Run Emerald Vault

In a terminal window run emerald vault.

$ emerald vault 
< No output just like the Unix way :P > 

Run Emerald TestRPC

Within the DApp directory, run emerald testrpc to run a local test net Ethereum Classic blockchain

$ emerald testrpc foo
address: <account address>
private key: <account's private key>

Emerald TestRPC will print several addresses and private keys associated with the test net instance. Leave this terminal open for reference to these accounts and addresses.

{% hint style="warning" %} Emerald Vault will automatically import the first testRPC account. {% endhint %}

Open Emerald Wallet

In a new terminal window, run emerald wallet to launch the Emerald Wallet.

$ emerald wallet

Import an Emerald TestRPC account using an account's private key. Emerald Wallet will ask for a password for the account.

Emerald Wallet now has an ETC account to start interacting with DApps.

Launch The DApp

The Emerald Starter Kit uses utilizes React. In the working DApp directory:

Install package dependencies.

$ npm install

Deploy the Emerald DApp with emerald deploy

$ emerald compile
$ emerald deploy

Launch the DApp

 $ npm start

{% hint style="info" %} By default Emerald starter-kit launches to http://localhost:8080/ {% endhint %}

Interact with the Smart Contract

The App Bar has an Account selector. These accounts are associated with the Emerald TestRPC Account that was imported into Emerald Wallet. When adding a new ToDo item, the Emerald Wallet will be prompted to open and sign the transaction. When the transaction is signed, the ToDo item will be added to the list.

Enter Hello World into the ToDo text field and click Send Transaction.

Allow the DApp to access Emerald Wallet. Continue to review and sign the transaction.

When the transaction is submitted, the ToDo item should have been added to the ToDo list.

Congratulations, you've just used an Emerald DApp using a Test Net!