0

I have an ERC20 token deployed on mainnet and I would like to transfer tokens from my wallet to a new contract and use it as the total supply of the new contract. Any help would be highly appreciated.

  • You need to make sure your new contract can accept ERC20 tokens. – AnAllergyToAnalogy Mar 26 '18 at 12:19
  • You have an ERC20 token, and want to use the tokens assigned to the wallet as the total supply of a new ERC20 token contract. Did I understand that correctly? – Ismael Mar 27 '18 at 19:52
0

I vant to suck your... tokens?

An interesting question. Presumably you wish to permanently consume tokens from the parent token (so they are no longer recoverable) and then issue an equivalent number of tokens in the new contract.

Essentially the easiest way to do this will be to set up a standard ERC20 contract with a 0 initial supply and get a donor to approve() (in the parent contract) for the new contract to transfer on their behalf.

Donor who holds the tokens in the old "parent" contract will call:

oldContract.approve(newContractAddress, tokenValue);

When the owner calls a function in the new contract, it will initiate the transfer, perform the minting of the coins, and set a bool so that it can never happen again.

New contract will call:

oldContract.transferFrom(donorAddress, this, tokenValue);

The new contract will thus forever hold the tokens from the old contract and they will never be able to be freed up or transferred elsewhere.

Example

Here's a brief example, it's missing the standard ERC20 junk you can find everywhere, but contains the bit that demonstrates the initialisation of the token.

pragma solidity ^0.4.21;

// Insert ERC20 interface here...

/// @title Vampire is an ERC20 token that will get its initial supply
/// of tokens by sucking from an existing token.  
contract Vampire is ERC20, Ownable {
    // Insert all standard ERC20 functions here...

    bool fed; // Once we have first fed, we have converted to a vampire.

    /// @notice Will feed off a `_parent` contract `_value` tokens from `_from`.
    /// @dev Requires `_from` to approve the transfer of tokens by `this`.
    /// @param _parent The address of the token we will feed off.
    /// @param _from The address that has given it's consent.
    /// @param _value The amount we are allowed to take.
    function suck(address _parent, address _from, uint _value) {
        require(!fed && msg.sender == owner);
        fed = true;
        supply = _value;
        balances[msg.sender] = _value;
        emit Transfer(address(0), msg.sender, _value);
        ERC20(_parent).transferFrom(_from, address(this), _value);
    }
}
  • If this answered your question, please mark it as the correct answer. If not let me know so I can further assist. – norganna Apr 2 '18 at 3:03

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.