I am starting a crowdsale and I want to add a custom function to my crowdsale contract. Basically I want users to be able to purchase tokens for fiat and bitcoins.

In order to make that work I will create a wallet with some ether and once a user purchase my tokens with a fiat transaction I want to send the equivalent amount of ether to my contract from my wallet address, convert the amount to the equivalent number of tokens, then transfer the tokens to the investor's address.

Is there a way to do that?

2 Answers 2


This is not the way it works except if you want to build an exchange. Ethereum don't know what fiat or bitcoin are. Only Ether is valid on the chain. So you'll have to accept Ether only in your contract. Users will have to buy Ether first from an Exchange using fiat or BTC for instance and then send it to your contract.

  • No I know that. As I said, I will create a separate wallet with ethereum and do a quick exchange based on the ethereum value from coinmarketcap. Basically what I am asking is how can I call a function in my contract that requires ethereum to be sent to it? Or in other words how can I make my function require and accept ethereum as a parameter
    – Zaid Amir
    Feb 12, 2018 at 17:47
  • That's not clear what you want to do. Sorry. Feb 12, 2018 at 17:50
  • I think it was pretty clear. Anyways, I figured it out.
    – Zaid Amir
    Feb 13, 2018 at 18:09
  • @ZaidAmir in that case feel free to answer you own question. I'm very sorry I wasn't able to help you. But you solved your problem so it's a happy ending. Feb 13, 2018 at 18:26

Well the solution was simple enough, just create a function that can only be called by the owner and transfer funds to whichever wallet address.

function FreeTransfer(address _investor, uint tokens) public onlyOwner returns (bool success) {
       return transfer(_investor, tokens);

function transfer(address to, uint tokens) public returns (bool success) {
        balances[msg.sender] = safeSub(balances[msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        Transfer(msg.sender, to, tokens);
        return true;

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