TransWikia.com

Self-destributing token contract template

Ethereum Asked by Vesa on November 15, 2021

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

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.

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

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

Answered by Jesbus on November 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP