{"action":"created","issue":{"url":"https://api.github.com/repos/OpenZeppelin/openzeppelin-solidity/issues/953","repository_url":"https://api.github.com/repos/OpenZeppelin/openzeppelin-solidity","labels_url":"https://api.github.com/repos/OpenZeppelin/openzeppelin-solidity/issues/953/labels{/name}","comments_url":"https://api.github.com/repos/OpenZeppelin/openzeppelin-solidity/issues/953/comments","events_url":"https://api.github.com/repos/OpenZeppelin/openzeppelin-solidity/issues/953/events","html_url":"https://github.com/OpenZeppelin/openzeppelin-solidity/issues/953","id":325744767,"number":953,"title":"Invalid token amount in Crowdsale buyTokens function","user":{"login":"vittominacori","id":8151143,"avatar_url":"https://avatars3.githubusercontent.com/u/8151143?v=4","gravatar_id":"","url":"https://api.github.com/users/vittominacori","html_url":"https://github.com/vittominacori","followers_url":"https://api.github.com/users/vittominacori/followers","following_url":"https://api.github.com/users/vittominacori/following{/other_user}","gists_url":"https://api.github.com/users/vittominacori/gists{/gist_id}","starred_url":"https://api.github.com/users/vittominacori/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vittominacori/subscriptions","organizations_url":"https://api.github.com/users/vittominacori/orgs","repos_url":"https://api.github.com/users/vittominacori/repos","events_url":"https://api.github.com/users/vittominacori/events{/privacy}","received_events_url":"https://api.github.com/users/vittominacori/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-23T14:55:41Z","updated_at":"2018-05-23T22:17:22Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"## 🎉 Description\r\n\r\nInvalid token amount in Crowdsale buyTokens function.\r\n\r\n- [x] 🐛 This is a bug report.\r\n- [ ] 📈 This is a feature request.\r\n\r\n## 💻 Environment\r\n\r\nIt is for all OpenZeppelin versions, using all networks and all deployment tools.\r\n\r\n## 📝 Details\r\n\r\nHi guys, I don't know if this could be considered as an issue or not.\r\n\r\nMy question is: \r\nif token has not 18 decimals (but for instance 10), how the **[_getTokenAmount](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/crowdsale/Crowdsale.sol#L186)** function should work?\r\n\r\nIt is using **_weiAmount** to multiply with **rate** and it means that we are using a 18 decimals number to calculate the token amount to transfer or mint to the beneficiary. \r\nSo if my token has 10 decimals (instead of 18 like the weiAmount) I will transfer about 8 decimals less of tokens than expected. And 8 decimal less means 10^8 tokens more than expected...\r\n\r\nIt is as described or am I missing something?\r\n\r\n## 🔢 Code To Reproduce Issue\r\n\r\nDeploy a MintableToken with 10 decimals.\r\nStart a MintedCrowdsale with a rate of 1.\r\nThen send 0.5 ETH to the Crowdsale.\r\n**It returns 50,000,000 of tokens instead of 0.5.**\r\n\r\nFunction to investigate is:\r\n\r\n```\r\nfunction _getTokenAmount(uint256 _weiAmount)\r\n    internal view returns (uint256)\r\n{\r\n    return _weiAmount.mul(rate);\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/OpenZeppelin/openzeppelin-solidity/issues/comments/391514473","html_url":"https://github.com/OpenZeppelin/openzeppelin-solidity/issues/953#issuecomment-391514473","issue_url":"https://api.github.com/repos/OpenZeppelin/openzeppelin-solidity/issues/953","id":391514473,"user":{"login":"Heph789","id":20362850,"avatar_url":"https://avatars3.githubusercontent.com/u/20362850?v=4","gravatar_id":"","url":"https://api.github.com/users/Heph789","html_url":"https://github.com/Heph789","followers_url":"https://api.github.com/users/Heph789/followers","following_url":"https://api.github.com/users/Heph789/following{/other_user}","gists_url":"https://api.github.com/users/Heph789/gists{/gist_id}","starred_url":"https://api.github.com/users/Heph789/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Heph789/subscriptions","organizations_url":"https://api.github.com/users/Heph789/orgs","repos_url":"https://api.github.com/users/Heph789/repos","events_url":"https://api.github.com/users/Heph789/events{/privacy}","received_events_url":"https://api.github.com/users/Heph789/received_events","type":"User","site_admin":false},"created_at":"2018-05-23T22:17:22Z","updated_at":"2018-05-23T22:17:22Z","author_association":"NONE","body":"Did you send .5 wei to the crowdsale or .5 ETH? Because the crowdsale operates in wei. So if you set the rate to 1, you're really saying 1 token for 1 wei. So if .5 ETH is put in, the amount of tokens returned should be way more than .5. 1 ETH = 10^18 wei. The amount of tokens returned should be .5 * 10^18 or 5 * 10^17. But the amount of tokens actually returned was 5 * 10^7. There's still a problem here, but there are too little tokens instead of too many I think."}}
{"actor":{"display_login":"Heph789"}}