-
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
Open
MichalisG
wants to merge
17
commits into
initial
Choose a base branch
from
master
base: initial
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
PR #1
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
11458e5
The Contracts
9499bf5
deploy and distribute
b9ceb19
fixed method calls
91a0add
clean code
e168de9
mpn pacage
7419297
empty commit
6bd8e81
instruction to run code
MichalisG 8284505
fixed readme
MichalisG 15b8e14
fixed transfer bug
f6cace9
Merge branch 'master' of https://github.com/MichalisG/SmartContract
e4971de
package
c20f532
Instructions to run the code
MichalisG ad56048
fixed white space
82c31f1
deleted unnecessary function
75c9748
fixed let to const
827ab75
npm init to fix the import bug
378dbdb
Merge branch 'master' of https://github.com/MichalisG/SmartContract
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| const Web3 = require('web3'); | ||
| const fs = require('fs'); | ||
| const util = require('util'); | ||
|
|
||
| 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)); | ||
|
|
||
|
|
||
|
|
||
| //main function | ||
| const run = async () => { | ||
| const b_addresses = Object.keys(balancesheet); | ||
| const b_values = Object.values(balancesheet); | ||
| //Deploy CappedMintableToken | ||
| const CappedMintableToken = await deployContract('./build/contracts/CappedMintableToken.json', account, [1000000]); | ||
|
|
||
| //Deploy TokenDistribution | ||
| const 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(); | ||
|
|
||
| try { | ||
| await TokenDistribution.methods.distribute(b_addresses, b_values).send({ from: account.address, gas: 800000 }); | ||
| } | ||
| catch (err) { | ||
| throw err; | ||
| } | ||
| for (let i = 0; i < b_addresses.length; i++) { | ||
| balance = await CappedMintableToken.methods.balanceOf(b_addresses[i]).call(); | ||
| } | ||
| balance = await CappedMintableToken.methods.balanceOf(TokenDistribution.options.address).call(); | ||
| }; | ||
|
|
||
| //helper function to deloy contracts | ||
| const deployContract = async (contractPath, account, args) => { | ||
| // Read the JSON file contents | ||
| const file = util.promisify(fs.readFile); | ||
| const contractJsonContent = await file(contractPath); | ||
| const jsonOutput = JSON.parse(contractJsonContent); | ||
|
|
||
| // Retrieve the ABI | ||
| const abi = jsonOutput.abi; | ||
|
|
||
| const bytecode = jsonOutput.bytecode; | ||
|
|
||
| const tokenContract = web3.eth.Contract(abi); | ||
|
|
||
| tokenContract.options.data = bytecode; | ||
|
|
||
| return tokenContract.deploy({ arguments: args }).send({ from: account.address, gas: 2000000, }); | ||
| } | ||
|
|
||
| run(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| pragma solidity ^0.5.0; | ||
|
|
||
| import "openzeppelin-solidity/contracts/token/ERC20/ERC20Capped.sol"; | ||
|
|
||
| contract CappedMintableToken is ERC20Capped{ | ||
|
|
||
| constructor(uint256 cap) ERC20Capped(cap) public {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
constThere 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.
Balance is used as a variable the value changes.