In this tutorial series we’ll create a Token Factory using Ethereum. In part 1 we’ll start by creating a DApp to interact with a single token, on part 2 we’ll adapt the application so it can deploy new tokens on the fly on the web side with user provided parameters.
A Token is typically a unit used to represent a medium of exchange for some service or utility. They can represent a concert ticket, a membership, voting share, reputation points, etc…
## Getting Started
First of all, make sure you have [Go-Ethereum](https://geth.ethereum.org/) and Embark installed.
{% code_block copyBtn:true %}
$ npm -g install embark
{% endcode_block %}
Now, let’s create a new dapp
{% code_block copyBtn:true %}
$ embark new TokenFactory
{% endcode_block %}
This will create a directory called TokenFactory, cd to it and run:
To exit the dashboard you can type 'exit' in the console or press CTRL+C.
{% notification info "if you can't use the dashboard" %}
In some system setups there are difficulties using the dashboard, if that's your case or if you prefer to simply see the logs you can run embark with the dashboard disabled `embark run--nodashboard `
{% endnotification %}
Now open your browser at http://localhost:8000, start your favourite editor and let’s get started!
## Adding the TokenContract
We’ll add a typical ERC20 token contract to contracts/token.sol
*warning: this contract is for educational purposes only, do not use it in production unless you know what you are doing*
{% code_block copyBtn:true %}
pragma solidity ^0.4.23;
contract Token {
event Transfer(address indexed from, address indexed to, uint value);
We haven't supplied any parameters to the contract and embark complains because the contract constructor takes a *initial_balance* parameter which we haven’t specified:
```
constructor(uint initial_balance) public {
_balances[msg.sender] = initial_balance;
_supply = initial_balance;
}
```
Let’s rectify this by specifying the *initial_balance* value in `config/contracts.js`
{% code_block copyBtn:true %}
module.exports = {
default: {
// .....
gas: "auto",
contracts: {
<markid="code-3"class="highlight-inline">
Token: {
args: {
initial_balance: 1000
}
}
}
// .....
}
}
{% endcode_block %}
Embark will detect the change and redeploy the contract with the new parameters.
You can confirm that the token supply is 1000 by typing:
For the sake of brevity, we wouldn’t implement every single functionality in the contract. However, we’ll implement two important features: Checking balance of an address and Transferring Tokens from one address to another.
## Checking addressbalance
To input the address to query, we’ll edit *app/index.html* and add a simple form.
Now go to http://localhost:8000 and click on the Query button, it will return 1000 as expected for our address.
## Transferring Tokens
Now let’s implement transferring tokens!
Now checking the contract, this is the method for transferring tokens:
```
function transfer( address to, uint value) returns (bool ok)
```
The method will take two parameters, an address and a value. Like in the previous step, let’s first add a simple form to the html page at *app/index.html*:
In this tutorial we deployed and interacted with single Token. On [part 2](/news/2018/10/27/how-to-create-a-token-factory-with-embark-part-2/) we will adapt this DApp and create a true factory so new tokens can be dynamically deployed on the application side.