Suppose I'm running an ICO and accepting other coins, in addition to ether. Whenever somebody sends me her bitcoins, I need to update her token balance.

Question: how do I make my smart contract "know" that the bitcoins are received? Not just bitcoins, any other altcoins.

In other words, whenever somebody sends her money to a certain bitcoin (or litecoin) wallet, I need to receive a notification. Is it possible?


There's no way to directly accept btc or other altcoins in a smart contract. You would have to code some system yourself that receives btc and then buys the tokens. This could be as simple as writing down who deposited what cryptocurrency at which exchange rate and then transferring the corresponding tokens or you could do a full fledged app that exchanges the btc/altcoins for eth with the Shapeshift API (https://info.shapeshift.io/) and interacts with your contract through a web app.

  • Actually what I need is some service that notifies me when I receive funds, but Shapeshift API seems to do something close -- checks for recent transactions, so I might use it for my purpose.
    – ulu
    Nov 1 '17 at 21:04

Obviously right now you can't accept any other coins than ETH or ERC20 coins natively in a smart contract. What I'd do is:

  • create a struct in your contract to hold other coins, for example:

    struct ExternalCoin {
      string symbol;
      uint amount;
  • create a global variable that can look like this:

    mapping (address => Distributor) public externalCoins
  • create a function that can update the above variable, only if it's called by the contract owner

  • receive the external coins in external wallets

  • create an app that detects when a new payment arrived

  • make the above app update the externalCoins data

Update based on the comment

Assuming you wish to receive bitcoins (who wouldn't, lol) for your token, you can do the following:

  • install a local running bitcoin node and interact with it through its json-rpc interface from your preferred language
  • generate an address for each of your buyers using the getnewaddress API endpoint
  • periodically run a script that monitors all the generated addresses for incoming payments using the listunspent API endpoint
  • store the transaction id of the payment in a DB or some other way and only credit your buyer's accounts for the transactions that are not already credited

Given how many BTC forks are out there, the same workflow (with the exact same API calls) should work for at least several other coins: Bitcoin Cash, Litecoin, Dash, Monero, Zcash and most probably Bitcoin Gold.

  • Thanks, but my question is about "create an app that detects when a new payment arrived" -- how do I do this detection?
    – ulu
    Nov 1 '17 at 20:56
  • Thanks a lot for the updated answer! I wish I could mark both answers as correct. Upvoting..
    – ulu
    Nov 2 '17 at 20:50

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.