# How can I accept Bitcoin payment in a smart contract? What would be the code for that?

I will create my personal token and I would like to be able to sell it for ETH and BTC. I know how to add the sell function for ETH, but how can I sell the tokens for BTC?

The ETH sell function I will use is the following:

function sell(uint256 amount) {
if (balanceOf[msg.sender] < amount ) throw;
balanceOf[this] += amount;
balanceOf[msg.sender] -= amount;
msg.sender.send(amount * sellPrice);
Transfer(msg.sender, this, amount);
}

• can someone explain me in detail how this will work? i am beginner and have written test ICO contract which accept ethers and would now like to extend it for bitcoins. – Ether Oct 31 '17 at 9:41

This is not as easy as with ETH, since a contract cannot own a BTC address. However you can use services like http://btcrelay.org/ which allow you to watch a btc address.

Quoted from Vitalik Buterin on reddit: (https://www.reddit.com/r/ethereum/comments/4d5z1y/is_it_possible_for_bitcoin_to_live_on_the/)

BTC -> ethereum convertibility can be done fine; the hard part is the ethereum -> BTC conversion. There would need to be some kind of sidechain protocol that can "understand" receipts being created on the ethereum blockchain; this is nontrivial and would have to be done as a softfork and accepted by BTC miners; if you don't want to do this, then the two alternative routes are (1) a federated multisig peg with independent and known parties, and (2) a multisig peg with security deposits on ethereum to incentivize participants to sign transactions correctly. (2) does rely on ETH continuing to have value and not dropping too quickly though, as otherwise the collateral may suddenly be insufficient to provide an adequate incentive not to steal the BTC.

You can have a process to convert BTC to WBTC which is a 1:1 ERC20 token. https://www.wbtc.network/

## protected by Community♦Jan 18 at 10:34

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).