Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions contracts/MyToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ contract MyToken is StandardToken {
string public symbol;
uint8 public constant decimals = 18;

uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals));

/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor(string _name, string _symbol, address _owner)
constructor(string _name, string _symbol, address _owner, uint256 _initialSupply)
public
{
name = _name;
symbol = _symbol;
totalSupply_ = INITIAL_SUPPLY;
balances[_owner] = INITIAL_SUPPLY;
emit Transfer(0x0, _owner, INITIAL_SUPPLY);
totalSupply_ = _initialSupply * (10 ** uint256(decimals));
balances[_owner] = totalSupply_;
emit Transfer(0x0, _owner, totalSupply_);
}

}
4 changes: 2 additions & 2 deletions contracts/MyTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ contract MyTokenFactory is Factory {
/// @param _name String for token name.
/// @param _symbol String for token symbol.
/// @return Returns token address.
function create(string _name, string _symbol)
function create(string _name, string _symbol, uint256 _initialSupply)
public
returns (address tokenAddress)
{
tokenAddress = new MyToken(_name, _symbol, msg.sender);
tokenAddress = new MyToken(_name, _symbol, msg.sender, _initialSupply);
register(tokenAddress);
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@
"redux-auth-wrapper": "^1.0.0",
"redux-saga": "^0.15.3",
"redux-thunk": "^2.2.0",
"truffle": "^4.1.7"
"truffle": "^4.1.11"
},
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"deployRinkeby": "truffle deploy --network rinkeby",
"test": "node scripts/test.js --env=jsdom",
"chain": "geth --datadir=\"/tmp/eth/60/01\" --nodiscover --maxpeers 0 --port 30301 --rpc --rpcapi \"db,eth,net,web3\" --rpcport 8101 --verbosity 6 console",
"coverage": "./node_modules/.bin/solidity-coverage",
"compile": "rm -dr ./build & truffle compile",
"ganache": "ganache-cli -p 9545 -m 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat' > /dev/null &",
"test:truffle": "npm run ganache sleep 5 && npm run lint && truffle test && npm run stop",
"stop": "sudo kill `sudo lsof -t -i:9545`",
Expand Down
73 changes: 42 additions & 31 deletions src/layouts/home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
FormGroup,
Input,
Row,
Button } from 'reactstrap'
Button
} from 'reactstrap'


class Home extends Component {
Expand All @@ -34,28 +35,28 @@ class Home extends Component {
this.state = {
tokenName: '',
tokenSymbol: '',
tokenInitialSupply: '',
tokenAddress: '',
receipt:'',
receipt: '',
error: '',
visible: true,
sendingMessage:'',
successMessage:''
sendingMessage: '',
successMessage: ''
}
}

async handleDeployToken() {
if(!this.state.tokenName || !this.state.tokenSymbol) {
if (!this.state.tokenName || !this.state.tokenSymbol) {
this.setState({ visible: true })
this.setState({ error: 'Please provide all values.'})
this.setState({ error: 'Please provide all values.' })
} else {
this.setState({ error: '' })
this.setState({ visible: true })
this.setState({ sendingMessage: 'Transaction Pending - Confirm through Metamask' })

try {
const nonce = await this.web3.eth.getTransactionCount(this.props.accounts[0])
console.log(nonce)
this.setState({ receipt: await this.contracts.MyTokenFactory.methods.create(this.state.tokenName, this.state.tokenSymbol).send( { nonce: nonce } ) })
this.setState({ receipt: await this.contracts.MyTokenFactory.methods.create(this.state.tokenName, this.state.tokenSymbol, this.state.tokenInitialSupply).send({ nonce: nonce }) })
this.setState({ tokenAddress: this.state.receipt.events.ContractInstantiation.returnValues.instantiation })
this.setState({ sendingMessage: '' })
this.setState({ successMessage: 'Token deployed!' })
Expand Down Expand Up @@ -85,13 +86,13 @@ class Home extends Component {
<CardImg src={logo} className="center-block img-responsive" alt="drizzle-logo" id="logo" />
<CardBody>
<CardTitle>
My Token Deployer
My Token Deployer
</CardTitle>
<CardText>
Simply select your Token name and symbol and click deploy!
Simply select your Token name and symbol and click deploy!
</CardText>
<CardText>
My deploying account: {this.props.accounts[0]}
My deploying account: {this.props.accounts[0]}
</CardText>
<Form className="pure-form pure-form-stacked">
<FormGroup>
Expand All @@ -113,31 +114,41 @@ class Home extends Component {
placeholder="Token Symbol"
/>
</FormGroup>
<FormGroup>
<Input
name="tokenInitialSupply"
type="text"
maxLength="3"
value={this.state.tokenInitialSupply}
onChange={this.handleInputChange}
placeholder="Token Initial Supply"
/>
</FormGroup>
{this.state.error &&
<Alert
color="danger"
isOpen={this.state.visible}
toggle={this.onDismiss}>
{this.state.error}
</Alert>
<Alert
color="danger"
isOpen={this.state.visible}
toggle={this.onDismiss}>
{this.state.error}
</Alert>
}
{this.state.sendingMessage &&
<Alert
color="light"
isOpen={this.state.visible}>
{this.state.sendingMessage}
<div className="loader">
<img src={loader} className="img-fluid" alt="" id="loader"></img>
</div>
</Alert>
<Alert
color="light"
isOpen={this.state.visible}>
{this.state.sendingMessage}
<div className="loader">
<img src={loader} className="img-fluid" alt="" id="loader"></img>
</div>
</Alert>
}
{this.state.successMessage &&
<Alert
color="success"
isOpen={this.state.visible}
toggle={this.onDismiss}>
{this.state.successMessage}
</Alert>
<Alert
color="success"
isOpen={this.state.visible}
toggle={this.onDismiss}>
{this.state.successMessage}
</Alert>
}
<Button color="primary" className="pure-button" type="button" onClick={this.handleDeployToken}>Deploy my Token!</Button>
</Form>
Expand Down
11 changes: 6 additions & 5 deletions test/MyTokenFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract('MyTokenFactory', accounts => {
const owner = accounts[0]
const tokenName = 'MyToken'
const tokenSymbol = 'MTS'
const INITIAL_SUPPLY = 1e+22
const INITIAL_SUPPLY = 200

beforeEach(async () => {
// [accounts[0], accounts[1]], requiredConfirmations, dailyLimit
Expand All @@ -17,8 +17,8 @@ contract('MyTokenFactory', accounts => {
})

it('Deploys and gives Tokens to msg.sender', async () => {
//Create Factory Contract
const token = await factoryInstance.create(tokenName, tokenSymbol, {from: owner})
//Create Factory Contract
const token = await factoryInstance.create(tokenName, tokenSymbol, INITIAL_SUPPLY, { from: owner })
const tokenAddress = utils.getParamFromTxEvent(token, 'instantiation', null, 'ContractInstantiation')

//Check owner has instantiation of token contract
Expand All @@ -36,10 +36,11 @@ contract('MyTokenFactory', accounts => {
const name = await tokenInstance.name()
const symbol = await tokenInstance.symbol()
const balanceOwner = await tokenInstance.balanceOf(owner)

console.log(balanceOwner)
console.log(INITIAL_SUPPLY)
//check they are all the same
assert.equal(name, tokenName)
assert.equal(symbol, tokenSymbol)
assert.equal(balanceOwner, INITIAL_SUPPLY)
assert.equal(balanceOwner.toString(10), (INITIAL_SUPPLY) * (10 ** 18))
})
})