How to Integrate 0xBitcoin in a Dapp


#1

This will only be a brief guide and assumes you know solidity.

If you only care about interface with 0xBitcoin for transfers and for value (not minting via contract) then I recommend just using this interface:

contract ERC20Interface {
    function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);
    function transferFrom(address from, address to, uint tokens) public returns (bool success);
   
    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
     }

If you also want to use the 0xBitcoin mint() method in Solidity (you probably are not doing this unless you are a fancy mining pool developer) then use this interface

contract ERC918Interface {
  function totalSupply() public constant returns (uint);
  function getMiningDifficulty() public constant returns (uint);
  function getMiningTarget() public constant returns (uint);
  function getMiningReward() public constant returns (uint);
  function balanceOf(address tokenOwner) public constant returns (uint balance);

  function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success);
 
  event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);

}

Now you can use it like this …

First, define the contract address as it is on the blockchain:

address 0xBitcoinContract = 0xb6ed7644c69416d67b522e20bc294a9a9b405b31;

Now call some methods…

ERC20Interface(0xBitcoinContract).balanceOf(this)

This will return the token balance inside your smart contract.

require ( ERC20Interface(0xBitcoinContract).transfer(to,amount) )

This will transfer tokens from your contract to another address

Example :

Have fun


#2

Wicked, nice and clear!

A guide on how to “Accept” 0xBitcoin through a pay function that can be called through web3 would be a great addition to this.


#3

I’ve added some variables to the interface:

contract ERC20Interface {

uint8 public decimals;

string public symbol;

string public name;

function totalSupply() public view returns (uint);

function balanceOf(address tokenOwner) public view returns (uint balance);

function allowance(address tokenOwner, address spender) public view returns (uint remaining);

function transfer(address to, uint tokens) public returns (bool success);

function approve(address spender, uint tokens) public returns (bool success);

function transferFrom(address from, address to, uint tokens) public returns (bool success);


event Transfer(address indexed from, address indexed to, uint tokens);

event Approval(address indexed tokenOwner, address indexed spender, uint tokens);

}