1

I have a Erc20 token X and an Smart Contract A

Smart Contract A contains 1000 X Tokens.

How can an User get an defined amount of X Tokens from this Smart Contract? (something like an Airdrop)

So Basically a user should call a method like: getAirdrop() and then should get 100 X tokens from A's wallet

I tried the following:

function getAirdrop(){
    erc20TOken.transferFrom(this, msg.sender, 10000000000000000000);
}

... and...

function getAirdrop(){
    erc20TOken.increaseApproval(msg.sender, 100000000000000000000);
}

... but do not work.

  • Might be worth checking out a related question, as well as the source code of Airdropper for inspiration. – S0AndS0 May 23 at 16:52
0

But how can you be sure, that user has finalized all tasks to get tokens? I assume tokens should be sent manually by owner (or implemented on backend). But also interested in answers with more experience.

  • That's the baset way, make a multiairdrop contract to a list of address, by the way, theres a couple o dapps that to the same – Vultur 2 days ago
0

If the contract A owns the required tokens you can simply use the transfer function in the ERC20 token contract.

So something like this (assuming you have a reference erc20TOken to the actual token contract):

function getAirdrop() public { 
  erc20TOken.transfer(msg.sender, 100); 
}
0

Easy, I made this example for you:

    pragma solidity ^0.4.18;

//Made to Stackexchange question

contract ERC20 {
    function transfer(address _to, uint256 _value)public returns(bool);
    function balanceOf(address tokenOwner)public view returns(uint balance);
    function transferFrom(address from, address to, uint tokens)public returns(bool success);

}

contract SimpleAirdrop {

      ERC20 public token;

        function SimpleAirdrop(address _tokenAddr) public {
        token = ERC20(_tokenAddr);
}

  function getAirdrop() public {
    token.transfer(msg.sender, 100000000000000000000); //18 decimals token
  }

}

Remember, you need send tokens to contract.

You can see this compiling here: https://ethfiddle.com/EIxLLnYFDJ

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.