Self-destributing token contract template

Self-destributing token contract template


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.


Ethereum Asked by Vesa on November 15, 2021

2 Answers

2 Answers

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.

specifically, look under contracts/crowdsale in the code.

Answered by shaish on November 15, 2021

This is a very common feature in tokens.

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

pragma solidity ^0.4.23;

import "";

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);

Answered by Jesbus on November 15, 2021

Add your own answers!

Related Questions

Ask a Question

Get help from others!

© 2021 All rights reserved.