I wonder if this is possible -- I want to create a smart contract when I call the contract with ETH amount, GAS amount & a random ICO address, it will

  1. Send the amount of ETH with the specified GAS to the ICO address
  2. Automatically receive the ICO token and hold it in the contract. (The ICO token could be any ERC20 tokens)
  3. I might call it again for another ICO so the contract needs to hold multiple random ERC20 tokens.


2 Answers 2


This if of course possible, but not in the way you would probably like it. Every ICO works differently, so there is no general way to participate in them when you only know the contract address. You can however send the transaction bytecode to the contract and it will execute it.

To withdraw Ether or Tokens you can either code two simple functions (you should be able to do that yourself) or just use the executeBytecode() function as it can do everything you can do with a regular wallet.

Here is something that will do what you want:

function executeBytecode(address addr, bytes transactionBytecode, uint256 etherAmount){


  • Thanks a lot for this, I will dive more into the executeBytecode() Feb 28, 2018 at 9:37

You can do this, but I am not sure this makes much sense.

You can create a function that takes the ICO address, the ether amount, and the gas amount. This function just forwards this ether to the ICO's address that you input.

Every ICO saves a balance, in each of these, you will find a mapping variable. When you index this with your contract's address you will see how much you have.

Your contract (and all of the contracts that exist, except token-contracts) does not receive (hold) tokens. What happens instead, is that the ICOs contract balances, when you buy, show that an amount of the tokens belong to a particular address (your contract address in this case). So if you buy using the contract, your contract is the owner of the tokens and you will need to implement a function in your contract to move the tokens to your personal address (or any other address) at some point, if you do not do that, the tokens will be locked forever.

I hope this helps.

  • thanks for this, I guess the issue is not all ICOs are same, I am not sure if I can just send ETH blindly to an ICO address and expect it will issue me tokens. Feb 27, 2018 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.