• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

bitcoin core – Using sendtoaddress is failing using json-rpc and I don’t know why

Moussa by Moussa
February 23, 2024
in Bitcoin
0
peer discovery – how to obtain the IP addresses of nodes for mining pools?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


The steps i followed are i first load the wallet in a different method which works, then i check the balance of the wallet in a different method which works, and then I call this sendbitcoin method(below). I can see that the bitcoind server gets the message but it returns with a 500.

If i use bitcoin-cli it works however i need to add a -rpcwallet flag. It’s my understanding that since the wallet has been loaded i shouldn’t need to use flag. My wallets aren’t encrypted so i don’t believe i need to use a passphrase.

My bitcoin.conf file looks like this.

rpcuser=rpcuser
rpcpassword=rpcpassword
testnet=1
prune=550
server=1
dbcache=1000
[test]
debug=mempool
debug=rpc
dbcache=1000
rpcport=8332
rpcbind=0.0.0.0
rpcallowip=172.19.0.0/16
minconf=1
fallbackfee=0.00000001

And the method looks like.

func (w *Wallet) SendBitcoin(sendTo string, amount float64, coachID uint) (BitcoinTransaction, error) {

username := os.Getenv("RPC_USER")
password := os.Getenv("RPC_PASSWORD")
rpcURL := os.Getenv("BITCOIN_NODE_HOST")

if username == "" || password == "" || rpcURL == "" {
    log.Error("RPC_USER, RPC_PASSWORD, or BITCOIN_NODE_HOST environment variables are not set")
    return BitcoinTransaction{}, errors.New("RPC_USER, RPC_PASSWORD, or BITCOIN_NODE_HOST environment variables are not set")
}

// Prepare the RPC request payload
requestBody := map[string]interface{}{
    "jsonrpc": "1.0",
    "method":  "sendtoaddress",
    "params":  []interface{}{sendTo, amount},
    "id":      1,
}

logrus.Printf("request body : %v", requestBody)
logrus.Printf("Sending on wallet %v", w.Name)

jsonData, err := json.Marshal(requestBody)
if err != nil {
    log.Errorf("failed to marshal JSON request: %v", err)
    return BitcoinTransaction{}, fmt.Errorf("failed to marshal JSON request: %v", err)
}

logrus.Printf("JSON body : %v", jsonData)

client := &http.Client{}

req, err := http.NewRequest("POST", rpcURL, bytes.NewBuffer(jsonData))
if err != nil {
    log.Errorf("failed to create HTTP request: %v", err)
    return BitcoinTransaction{}, fmt.Errorf("failed to create HTTP request: %v", err)
}

req.SetBasicAuth(username, password)
req.Header.Set("Content-Type", "application/json")

// Send HTTP request
resp, err := client.Do(req)
if err != nil {
    log.Errorf("failed to send HTTP request: %v", err)
    return BitcoinTransaction{}, fmt.Errorf("failed to send HTTP request: %v", err)
}
//...

logs

[00] bitcoin      | 2024-02-22T22:36:59Z [rpc] ThreadRPCServer 
 method=loadwallet user=rpcuser
[00] rest-server  | time="2024-02-22T22:36:59Z" level=info msg="balance 
= 0.0003933699999999999, amount = 0.0001"
[00] bitcoin      | 2024-02-22T22:36:59Z Using SQLite Version 3.38.5
[00] bitcoin      | 2024-02-22T22:36:59Z Using wallet 
 /home/bitcoin/.bitcoin/testnet3/wallets/111-20240221
[00] bitcoin      | 2024-02-22T22:36:59Z [rpc] ThreadRPCServer 
method=sendtoaddress user=rpcuser
[00] rest-server  | time="2024-02-22T22:36:59Z" level=info msg="request 
 body : map[id:1 jsonrpc:1.0 method:sendtoaddress params: 
[tb1qljunwv4hv8nx3mwsrup4fse5zhahyjtmx0fwzl 0.0001 ]]"
[00] rest-server  | time="2024-02-22T22:37:00Z" level=info 
msg="unexpected status code: 500"



Source link

Related articles

Wallet Of Satoshi Partners With Spark To Offer Self-Custodial Bitcoin Lightning Experience

Wallet Of Satoshi Partners With Spark To Offer Self-Custodial Bitcoin Lightning Experience

July 1, 2025
Circle Announces Circle Gateway: No More Bridging USDC Across Multiple Chains?

Circle Announces Circle Gateway: No More Bridging USDC Across Multiple Chains?

July 1, 2025
Share76Tweet47

Related Posts

Wallet Of Satoshi Partners With Spark To Offer Self-Custodial Bitcoin Lightning Experience

Wallet Of Satoshi Partners With Spark To Offer Self-Custodial Bitcoin Lightning Experience

by Moussa
July 1, 2025
0

Today, Spark has announced a new integration with Wallet of Satoshi, one of the largest Bitcoin Lightning Network (LN) wallets,...

Circle Announces Circle Gateway: No More Bridging USDC Across Multiple Chains?

Circle Announces Circle Gateway: No More Bridging USDC Across Multiple Chains?

by Moussa
July 1, 2025
0

Stablecoin issuer Circle (NYSE: CRCL) announced on Tuesday that its flagship stablecoin asset USDC which currently has a market capitalization...

Can BIP 39 Seed Phrase Restore the Liquid and Lightning Coins in Blockstream Android?

by Moussa
July 1, 2025
0

Using the Blockstream Android wallet. I created a new wallet and put some on-chain coins in it, while I also...

Metaplanet Buys 1,111 Bitcoin, Robert Kiyosaki Sees BTC Crash

US Spot Bitcoin ETFs Push Inflows Streak To 15 Days

by Moussa
July 1, 2025
0

Join Our Telegram channel to stay up to date on breaking news coverage Spot Bitcoin ETFs (exchange-traded funds) extended their...

Bloomberg Analysts Predict 95% Chance of Solana, Litecoin, XRP ETF Approvals in 2025

by Moussa
July 1, 2025
0

Leading Bloomberg ETF analysts Eric Balchunas and James Seyffart think that the odds of the US Securities and Exchange Commission...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSUzQ2RpdiUyMGNsY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jB0eXBlJTNEJTIyY2hlY2tib3glMjIlMjBuYW1lJTNEJTIybnklMjIlMjByZXF1aXJlZCUyMGNsYXNzJTNEJTIydG5wLXByaXZhY3klMjIlM0UlQzIlQTBCeSUyMGNvbnRpbnVpbmclMkMlMjB5b3UlMjBhY2NlcHQlMjB0aGUlMjBwcml2YWN5JTIwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News