├── DockToken.sol ├── README.md └── distribution.sol /DockToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.18; 2 | 3 | /** 4 | * @title Ownable 5 | * @dev The Ownable contract has an owner address, and provides basic authorization control 6 | * functions, this simplifies the implementation of "user permissions". 7 | */ 8 | contract Ownable { 9 | address public owner; 10 | 11 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 12 | 13 | /** 14 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender account. 15 | */ 16 | function Ownable() public { 17 | owner = msg.sender; 18 | } 19 | 20 | /** 21 | * @dev Throws if called by any account other than the owner. 22 | */ 23 | modifier onlyOwner() { 24 | require(msg.sender == owner); 25 | _; 26 | } 27 | 28 | /** 29 | * @dev Allows the current owner to transfer control of the contract to a newOwner. 30 | * @param newOwner The address to transfer ownership to. 31 | */ 32 | function transferOwnership(address newOwner) public onlyOwner { 33 | require(newOwner != address(0)); 34 | OwnershipTransferred(owner, newOwner); 35 | owner = newOwner; 36 | } 37 | } 38 | 39 | contract DockToken is Ownable { 40 | function transfer(address to, uint256 value) public returns (bool); 41 | function transferFrom(address from, address to, uint256 value) public returns (bool); 42 | } 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Distribution contract 2 | 3 | Distribution contract is an ethereum counterpart of our distribution service. It is very simple and has only one method. 4 | This method is involved by our system to distribute tokens to several recipients in a single call and thus, save gas 5 | fees. 6 | 7 | ## Token allowance 8 | 9 | Neither distribution smart contract nor account of the contract owner do not store tokens. 10 | Tokens must be stored on a separate account that will provide allowance for **contract address** to distribute tokens 11 | on his behalf. 12 | 13 | ## How to setup allowance 14 | 15 | Guide below as well as distribution contract is designed for dock token, however, one can easily substitute dock 16 | token with any other ERC20 contract. 17 | 18 | 1. Open dock contract code (https://github.com/dockio/dock-token/blob/master/crowdsale.sol) 19 | 2. Make sure to have **Holder account** opened in Metamask and switch to MainNet (one that has a lot of tokens that 20 | will be allowed to be spent) 21 | 3. Open remix (https://remix.ethereum.org) and paste dock token contract there 22 | 4. Select ``Run`` tab 23 | 5. Select ``DockToken`` from the list of available contracts 24 | 6. In "Load from address" field enter dock token address. 25 | 7. Click "At address". You will see contract loaded underneath 26 | 8. Find red button "approve", in field next to it enter ``"", ``, 27 | ie ``"0xab31fe0f8c1e7d1a11fd89adec18652e53417936", 1045050000000000000000000`` which will allow 1045050 tokens to 28 | be spent by 0xab31fe0f8c1e7d1a11fd89adec18652e53417936 address. Notice 18 zeros. They are required and are equal 29 | to dock token decimals. 30 | 9. Hit red "approve" button, verify transaction details and approve it via MetaMask. 31 | 10. Wait for transaction to be mined and verify proper allowance. 32 | 33 | ## How to verify allowance. 34 | 35 | 1. Open dock token in EtherScan: https://etherscan.io/token/0xe5dada80aa6477e85d09747f2842f7993d0df71c#readContract 36 | 2. Select "Read Contract" 37 | 3. In "Allowance" enter **Holder address**, **Distribution address** (address of the distributed "Distribution" 38 | contract) and hit "Query" 39 | 4. You should see number of allowed tokens. Divide that number by 10^18 to get token amount. 40 | 41 | 42 | ## Deploy contract from Remix 43 | 44 | In order to deploy contract directly from Remix one should: 45 | 46 | 1. Open MetaMask plugin, select proper network and proper account 47 | 2. Load remix from https://remix.ethereum.org 48 | 3. Load required files 49 | 4. On the right select ``Run`` tab 50 | 5. Make sure that environment is set to be ``Injected Web3`` (that is one, provided by MetaMask) 51 | 5. Make sure proper account is selected 52 | 6. Select proper contract and provide proper constructor attributes 53 | 7. Hit Create and confirm transaction in MetaMask. 54 | 8. Wait for the magic to happen. -------------------------------------------------------------------------------- /distribution.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.18; 2 | 3 | import './DockToken.sol'; 4 | 5 | 6 | contract Distribution is Ownable { 7 | // Token to be distributed 8 | DockToken public token; 9 | 10 | function Distribution(address dockToken) public { 11 | token = DockToken(dockToken); 12 | } 13 | 14 | /** 15 | * Allocate tokens in bulk 16 | */ 17 | function distribute(address _from, address[] toList, uint256[] tokensList) external onlyOwner returns (bool) { 18 | require(toList.length == tokensList.length); 19 | 20 | for (uint32 i = 0; i < toList.length; i++) { 21 | if (!token.transferFrom(_from, toList[i], tokensList[i])) { 22 | revert(); 23 | } 24 | } 25 | return true; 26 | } 27 | } 28 | --------------------------------------------------------------------------------