ERC20 Token - is it possible to transfer part of tokens to a smart contract?

In October 2020, I used a free token generator https://vittominacori.github.io/erc20-generator/

Back then there were no paid plans like now so that token was simple, easy token with few customization like decimals, max supply, symbol, name. Without Mintable option.
It is possible to use the generated token, then transfer part of this tokens to the simple ICO contract and sell it to others?

Most of the example uses and tutorials describe how to generate a token and create an ICO with it. But how to use an already existing token and transfer part of it to an ICO contract? Is it possible?

1 Like

Hi @Tomy_R,

Welcome to the community :wave:

Assuming you have a fixed supply ERC20 token, then you could transfer any number of tokens to a crowdsale contract (or list on a decentralized exchange).

See the Simple ERC20 Crowdsale.

I also recommend going through Points to consider when creating a fungible token (ERC20, ERC777).

I still don’t understand.
Ok for example:
I created 1000 test tokens.

I want to sell half of them for Ether.
So:

  1. Which contract I have to use in Remix? Can You show me a simple example
    ie. 10 test tokens for 1 Ether
  2. Then I have to deploy this cotract to the testnet, rigt?
  3. I have to transfer 500 tokens manualy to this contract or what I have to do?
  4. If I send 1 ether to this contract I will receive 10 test tokens, right?

Please explain.
Thank You very much!

1 Like

Just like abcoathup mentioned above, I think what you need are all there.

You should use the crowdsale contract,

SimpleCrowdsale.sol
// contracts/SimpleCrowdsale.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.5;

import "@openzeppelin/contracts/crowdsale/Crowdsale.sol";

/**
 * @title SimpleCrowdsale
 * @dev This is an example of a fully fledged crowdsale.
 */
contract SimpleCrowdsale is Crowdsale {
    constructor(
        uint256 rate,
        address payable wallet,
        IERC20 token
    ) public Crowdsale(rate, wallet, token) {}
}

Yes!

Right!

Depends on the rate you set.

1 Like

should I enter these values in SimpleCrowdsale.sol
or in a different file?
Can you correct it because it shows me the error, please?

1 Like

If you want to test by the Remix, you should use the following way to import the dependency:

import  "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.1/contracts/crowdsale/Crowdsale.sol";

And it seems like you have trouble using Remix to test, you can have a look at this tutorial:

Create an ERC20 using Remix, without writing Solidity - General / Guides and Tutorials - OpenZeppelin Community

1 Like

I tested SimpleToken.sol and it’s working
but SimpleCrowdsale.sol not working
i have two errors

browser/SimpleCrowdsale.sol:13:23: ParserError: Expected type name uint256 rate, 10 ^^

and

creation of SimpleCrowdsale errored: Error encoding arguments: Error: invalid BigNumber string (argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.0.8)

1 Like

You should set these values when deploy rather than set in the code.

2 Likes

thank You very much! This solution resolves all my problems.

I love You mate

1 Like

Thanks @Skyge :pray: