Creates BCH tokens and send money between them for the Keoken protocol.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install keoken
It uses bitcoin-ruby, but you can use Trezor or Electrum, the most important command is the script, which you can obtain with token.hex, then you can send it as an output with a scriptPubKey and a value of 0. In order to crate a token you need two outputs, the change address with an amount less than original (for fees) and the other one for the script. To send money you need three outputs, the change address, the address who owns the recipient token and the script.
Create token and send it to the blockchain
Bitcoin.network = :testnet3 token = Keoken::Token.new(name: "test-keoken-bitex") token.create(1_000_000) key = Bitcoin::Key.from_base58("cShKfHoHVf6iYKZym18ip1MJFQFxJwbcLxW53MQikxdDsGd2ofBU") script = token.hex @transaction_token = Keoken::Backend::BitcoinRuby::Transaction.build_for_creation(key.addr, key, script) transaction = Keoken::Bitprim::Transaction.new transaction.send_tx(@transaction_token.raw)
Send token money and send transaction to the blockchain
Bitcoin.network = :testnet3 bitprim_transaction = Keoken::Bitprim::Transaction.new assets = bitprim_transaction.assets_by_address('mro9aqn4xCzXVS7jRFFuzT2ERKonvPdSDA') token = Keoken::Token.new(id: assets.first['asset_id']) token.send_amount(500_000) key = Bitcoin::Key.from_base58('cShKfHoHVf6iYKZym18ip1MJFQFxJwbcLxW53MQikxdDsGd2ofBU') script = token.hex @transaction_token = Keoken::Backend::BitcoinRuby::Transaction.build_for_send_amount(key.addr, 'mnTd41YZ1e1YqsaPNJh3wkeSUrFvp1guzi', key, script) transaction = Keoken::Bitprim::Transaction.new transaction.send_tx(@transaction_token.raw)
Bug reports and pull requests are welcome on GitHub at https://github.com/bitex-la/keoken-ruby.
The gem is available as open source under the terms of the MIT License.