0

Self-destributing token contract template

Hello,

Are there any complete templates or resources for making a token which distributes itself when funds are sent to the contract?

I. e. user sends 0.01 ETH to contract, which in turn sends X tokens back to user.

I would prefer blockchain based solutions but if none are available then maybe a server based solution.

Vesa

0

This is a very common feature in tokens.

Here's an incomplete example you can play around with:

pragma solidity ^0.4.23;

import "https://github.com/OpenZeppelin/zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";

contract TestToken is StandardToken
{
    uint256 public tokensPerEther = 1000;

    constructor() public
    {
        totalSupply_ = 10000;
        balances[this] = totalSupply_;
    }

    function() payable external
    {
        this.transfer(msg.sender, msg.value * tokensPerEther);
    }
}
  • Hi, thanks but I'm looking for a complete template and preferably including instructions too. – Vesa Apr 29 '18 at 13:14
0

Use this one, it's a very well tested implementation of token distribution contracts, which is used as a base for many projects in the ethereum space.

https://github.com/OpenZeppelin/openzeppelin-solidity

specifically, look under contracts/crowdsale in the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.