Crypto Flexs
  • DIRECTORY
  • CRYPTO
    • ETHEREUM
    • BITCOIN
    • ALTCOIN
  • BLOCKCHAIN
  • EXCHANGE
  • TRADING
  • SUBMIT
Crypto Flexs
  • DIRECTORY
  • CRYPTO
    • ETHEREUM
    • BITCOIN
    • ALTCOIN
  • BLOCKCHAIN
  • EXCHANGE
  • TRADING
  • SUBMIT
Crypto Flexs
Home»BITCOIN NEWS»wallet – Create and sign transactions locally in Ruby
BITCOIN NEWS

wallet – Create and sign transactions locally in Ruby

By Crypto FlexsMay 13, 20242 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Email
wallet – Create and sign transactions locally in Ruby
Share
Facebook Twitter LinkedIn Pinterest Email

So I’m using public node for Bitcoin node integration and previously I used sendtoaddress method to build, sign and broadcast transactions on the node. But now the sendtoaddress method is not allowed on public nodes due to privacy reasons due to private key disclosure, so we have to create, sign and broadcast the transaction locally offline. I’m using Ruby on Rails (openware/peatio). Here is my code so far: I am using the Bitcoinrb gem ( https://rubygems.org/gems/bitcoinrb ).

TESTNET_BASE_URL = "https://blockstream.info/testnet/api/address/".freeze
MAINNET_BASE_URL = "https://blockstream.info/api/address/".freeze



def create_transaction!(transaction, options = )
  env = @currency.dig(:key)&.include?('testnet') ? "testnet" : "mainnet"
  ::Bitcoin.chain_params=(env)
  key = ::Bitcoin::Key.new(priv_key: @wallet.fetch(:secret))
  url = @currency.dig(:key)&.include?('testnet') ? TESTNET_BASE_URL : MAINNET_BASE_URL
  response = URI.open(url + "#@wallet(:address)/utxo")
  utxos = JSON.parse(response.read)
  trx = build_trx(utxos.first, transaction.to_address, transaction.amount)
  trx = sign_transaction(trx, @wallet.fetch(:secret))


  signed_trx = client.json_rpc(:sendrawtransaction, "hexstring": trx.to_payload.bth, maxfeerate: 0)
  Rails.logger.warn  "-=-=-=sendrawtransaction-=-=- #signed_trx.inspect -=-=-=-=-=-=-=-=" 
  signed_trx
rescue Bitcoind::Client::Error => e 
  raise Peatio::Wallet::ClientError, e
end

def sign_transaction(tx, private_key)
  key = Bitcoin::Key.new(priv_key: private_key)
  tx.inputs.each_with_index do |input, index|
    script_pubkey = Bitcoin::Script.to_p2pkh(key.pubkey)
    input.script_sig = script_pubkey
  end
end

def build_trx(utxo, recipient_address, amount)
  tx = Bitcoin::Tx.new
  tx_in = Bitcoin::TxIn.new(out_point: Bitcoin::OutPoint.new(utxo("txid"), utxo("vout").to_i))
  tx.inputs << tx_in
  tx_out = Bitcoin::TxOut.new(value: amount.to_f, script_pubkey: Bitcoin::Script.to_p2pkh(recipient_address))
  tx.outputs << tx_out
  tx
end

However, the output of sendrawtrasnaction is:

"statusCode":403,"errorCode":"btc.blockchain.broadcast.error","message":"Unable to broadcast transaction.","cause":"Request failed with status code 500","dashboardLog":"https://dashboard.tatum.io/logs?id=663f683a798bb0f969fc3760"

Please let me know if I need to do it any other way. If I’m doing something wrong or missing something, I’d appreciate some help.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

Related Posts

Tether quietly adds 8,888 BTC, tapping 96,369 coins from Bitcoin Stash.

January 1, 2026

Bitcoin price limited due to Maco condition changes, not whale sales

December 26, 2025

You can trade ZKP!

December 20, 2025
Add A Comment

Comments are closed.

Recent Posts

Bitmine Publishes New Chairman’s Message Explaining Why Shareholders Should Vote YES To Approve The Amendment To Increase Authorized Shares

January 2, 2026

Husky Inu AI (HINU) will start trading in 2026 at $0.00024581.

January 2, 2026

Frontnode.com And The Question Of Trust How Responsible Bitcoin Onramps Shape Long-Term Adoption

January 2, 2026

A popular cryptocurrency founder has poured millions of dollars into Ethereum, and here’s what he’s buying:

January 2, 2026

Tether quietly adds 8,888 BTC, tapping 96,369 coins from Bitcoin Stash.

January 1, 2026

ASTER price outlook as whale loses 3 million coins

January 1, 2026

Cardano (ADA) Aims Higher – Bullish Setup Hints for New Legs

January 1, 2026

South Korea fines Korbit $1.8 million for failing to comply with regulations

January 1, 2026

Lighter Token (LIT) Overtakes Jupiter — Are Hyperliquids Dangerous?

January 1, 2026

3 Small Cap Altcoins to Watch in the 2026 Prediction Market Boom

December 31, 2025

Test proxy contracts securely using Wake Framework

December 30, 2025

Crypto Flexs is a Professional Cryptocurrency News Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of Cryptocurrency. We hope you enjoy our Cryptocurrency News as much as we enjoy offering them to you.

Contact Us : Partner(@)Cryptoflexs.com

Top Insights

Bitmine Publishes New Chairman’s Message Explaining Why Shareholders Should Vote YES To Approve The Amendment To Increase Authorized Shares

January 2, 2026

Husky Inu AI (HINU) will start trading in 2026 at $0.00024581.

January 2, 2026

Frontnode.com And The Question Of Trust How Responsible Bitcoin Onramps Shape Long-Term Adoption

January 2, 2026
Most Popular

Bitcoin Upside, ETF inflows can be stopped at $ 100k despite $ 3B.

April 28, 2025

Bitcoin derivatives hint at potential upside above $73,000 — next to hit all-time high

May 21, 2024

Hong Kong financial authorities issue warning to fraudulent banking websites

June 7, 2024
  • Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions
© 2026 Crypto Flexs

Type above and press Enter to search. Press Esc to cancel.