-
Notifications
You must be signed in to change notification settings - Fork 0
PR #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: initial
Are you sure you want to change the base?
PR #1
Changes from 12 commits
11458e5
9499bf5
b9ceb19
91a0add
e168de9
7419297
6bd8e81
8284505
15b8e14
f6cace9
e4971de
c20f532
ad56048
82c31f1
75c9748
827ab75
378dbdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # SmartContract | ||
| # Requirements | ||
| - Truffle Framework | ||
| ``` | ||
| npm install truffle -g | ||
| ``` | ||
| - [Ganache](https://truffleframework.com/ganache). | ||
|
|
||
| # Instalation | ||
| ``` | ||
| npm intall | ||
| truffle compile | ||
| ``` | ||
| # To Run | ||
| - Run Ganache first and after | ||
| - Execute command | ||
| ``` | ||
| node app.js | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| const Web3 = require('web3'); | ||
| const fs = require('fs'); | ||
|
|
||
| const account = { | ||
| address: '0x6D2D0C8d05D39B96FEf53a74B61e9974C0029a00', | ||
| key:'79f6211271c58baf8f2eb17651881a935584e845f06589dcfde811269f00c3ca' | ||
| }; | ||
|
|
||
| const balancesheet = { | ||
| '0xBFc79d03a9B592F93edb677e7815F9DA41C14475': 1000, | ||
| '0xF215e07458aa6ad6472961Ec407FAEDb65E5188C': 2000, | ||
| '0x422d16efDB1F60379E82a0a5EC8A71C35334790D': 3000, | ||
| '0x7158d92Ac4dbAd955E01DDa0a3b0b014224D055e': 4000, | ||
| '0x0AEDACa4451B87DB1704b9379f544785b46E2f02': 5000 | ||
| }; | ||
|
|
||
| const selectedHost = 'http://127.0.0.1:7545'; | ||
| const web3 = new Web3(new Web3.providers.HttpProvider(selectedHost)); | ||
|
|
||
| run(); | ||
|
|
||
| //main function | ||
| async function run(){ | ||
|
||
| let b_addresses = Object.keys(balancesheet); | ||
|
||
| let b_values = Object.values(balancesheet); | ||
|
||
| //Deploy CappedMintableToken | ||
| let CappedMintableToken = await deployContract('./build/contracts/CappedMintableToken.json', account, [1000000]); | ||
|
|
||
| //Deploy TokenDistribution | ||
| let TokenDistribution = await deployContract('./build/contracts/TokenDistribution.json', account, [CappedMintableToken.options.address]); | ||
|
|
||
|
|
||
| await CappedMintableToken.methods.mint(TokenDistribution.options.address, 15000).send({from: account.address}); | ||
|
||
|
|
||
| let balance = await CappedMintableToken.methods.balanceOf(TokenDistribution.options.address).call(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Balance is used as a variable the value changes. |
||
| console.log('Total balance: ' + balance); | ||
|
||
| try{ | ||
| await TokenDistribution.methods.distribute(b_addresses,b_values).send({from: account.address, gas: 800000}); | ||
|
||
| }catch(err){ | ||
|
||
| console.log(err); | ||
| } | ||
| for(let i=0; i<b_addresses.length; i++){ | ||
| balance = await CappedMintableToken.methods.balanceOf(b_addresses[i]).call(); | ||
| console.log(i+' ' +b_addresses[i] +': '+ balance); | ||
| } | ||
| balance = await CappedMintableToken.methods.balanceOf(TokenDistribution.options.address).call(); | ||
| console.log('Total balance: ' + balance); | ||
| }; | ||
|
|
||
| //helper function to deloy contracts | ||
| function deployContract(contractPath, account, args){ | ||
|
||
| return new Promise((resolve,reject)=>{ | ||
| // Read the JSON file contents | ||
| let contractJsonContent = fs.readFileSync(contractPath, 'utf8'); | ||
|
||
| let jsonOutput = JSON.parse(contractJsonContent); | ||
|
|
||
| // Retrieve the ABI | ||
| let abi = jsonOutput.abi; | ||
|
|
||
| let bytecode = jsonOutput.bytecode; | ||
| // console.log(bytecode); | ||
|
|
||
| let tokenContract = web3.eth.Contract(abi); | ||
|
|
||
| tokenContract.options.data = bytecode; | ||
|
|
||
| tokenContract.deploy({ | ||
| arguments: args | ||
| }) | ||
| .send({ | ||
| from: account.address, | ||
| gas: 2000000, | ||
| }) | ||
| .then((newContractInstance) => { | ||
| resolve(newContractInstance); | ||
| }).catch(err=>{ | ||
| console.log(err); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| pragma solidity ^0.5.0; | ||
|
|
||
| import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20Capped.sol"; | ||
|
||
|
|
||
| contract CappedMintableToken is ERC20Capped{ | ||
|
|
||
| constructor(uint256 cap) ERC20Capped(cap) public {} | ||
|
|
||
| function mint(address _to, uint256 _amount) public returns (bool){ | ||
|
||
| return super.mint(_to,_amount); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| pragma solidity ^0.5.0; | ||
|
|
||
| import "./CappedMintableToken.sol"; | ||
|
|
||
| contract TokenDistribution{ | ||
| address addr; | ||
|
|
||
| constructor(address _address) public{ | ||
| addr = _address; | ||
| } | ||
| function distribute(address[] memory contributors, uint256[] memory balances) public { | ||
| for(uint256 i=0; i<contributors.length; i++){ | ||
| CappedMintableToken(addr).transfer(contributors[i], balances[i]); | ||
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| const Migrations = artifacts.require("Migrations"); | ||
| const TokenDistribution = artifacts.require("TokenDistribution"); | ||
| const CappedMintableToken = artifacts.require("CappedMintableToken"); | ||
|
|
||
| module.exports = function(deployer) { | ||
| deployer.deploy(Migrations); | ||
| deployer.deploy(CappedMintableToken, 1000000).then(()=>{ | ||
| deployer.deploy(TokenDistribution, CappedMintableToken.address); | ||
| }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async 👍