truffle migrate --reset
tokenFarm = await TokenFarm.deployed()
truffle(development)> tokenFarm.address
'0x689cB867e929Cdd1c69b78B27fb11DAb86B6393e'
truffle(development)> name = tokenFarm.name()
'Dapp Token Farm'
truffle(development)> mDai = await DaiToken.deployed()
accounts = await web3.eth.getAccounts()
truffle(development)> accounts[1]
'0xBC7000c582225B1086020043f35a8bcE1DA910F6'
truffle(development)> balance = await mDai.balanceOf(accounts[1])
undefined
truffle(development)> balance
BN {
negative: 0,
words: [ 51380224, 30903128, 22204, <1 empty item> ],
length: 3,
red: null
}
truffle(development)> balance.toString()
'100000000000000000000'
truffle(development)> formattedBalance = web3.utils.fromWei(balance)
'100'
truffle(development)> web3.utils.toWei('1.5', 'Ether')
'1500000000000000000'
---------------------
//migrations/2_deploy_contract.js
const DappToken = artifacts.require('DappToken')
const DaiToken = artifacts.require('DaiToken')
const TokenFarm = artifacts.require('TokenFarm')
module.exports = async function (deployer, network, accounts) {
// Deploy Mock DAI Token
await deployer.deploy(DaiToken)
const daiToken = await DaiToken.deployed()
// Deploy Dapp Token
await deployer.deploy(DappToken)
const dappToken = await DappToken.deployed()
// Deploy TokenFarm
await deployer.deploy(TokenFarm, dappToken.address, daiToken.address)
const tokenFarm = await TokenFarm.deployed()
// Transfer all tokens to TokenFarm (1 million)
await dappToken.transfer(tokenFarm.address, '1000000000000000000000000')
// Transfer 100 Mock DAI tokens to investor
await daiToken.transfer(accounts[1], '100000000000000000000')
}
--------------------------
//src/componenets/contracts
pragma solidity ^0.5.0;
import "./DappToken.sol";
import "./DaiToken.sol";
contract TokenFarm{
string public name = "Dapp Token Farm";
DappToken public dappToken;
DaiToken public daiToken;
constructor(DappToken _dappToken, DaiToken _daiToken) public{
dappToken = _dappToken;
daiToken = _daiToken;
}
}
reference:
No comments:
Post a Comment