• 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

Texas Bitcoin Reserve Bill Clears Committee, Heads For Floor Vote

Texas Bitcoin Reserve Bill Clears Committee, Heads For Floor Vote

May 9, 2025
Trump Allegedly Misled on XRP Crypto Reserve Post, Report Claims

Trump Allegedly Misled on XRP Crypto Reserve Post, Report Claims

May 9, 2025
Share76Tweet47

Related Posts

Texas Bitcoin Reserve Bill Clears Committee, Heads For Floor Vote

Texas Bitcoin Reserve Bill Clears Committee, Heads For Floor Vote

by Moussa
May 9, 2025
0

Join Our Telegram channel to stay up to date on breaking news coverage A House Committee in Texas has passed...

Trump Allegedly Misled on XRP Crypto Reserve Post, Report Claims

Trump Allegedly Misled on XRP Crypto Reserve Post, Report Claims

by Moussa
May 9, 2025
0

President Donald Trump’s newly announced national crypto reserve made headlines fast, and not just because it included big-name tokens like...

Texas Advances Strategic Bitcoin Reserve Bill To Final Vote

Texas Advances Strategic Bitcoin Reserve Bill To Final Vote

by Moussa
May 9, 2025
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure Texas lawmakers have advanced the Strategic Bitcoin...

XRP Faces Make-Or-Break Moment Amid Bearish Threat

Dogecoin ‘Looks Incredible Here,’ Says Analyst — Here’s Why

by Moussa
May 9, 2025
0

Reason to trust Strict editorial policy that focuses on accuracy, relevance, and impartiality Created by industry experts and meticulously reviewed...

MARA Reports $214M In Q1 Revenue, Grows Bitcoin Holdings To 47,531 BTC

MARA Reports $214M In Q1 Revenue, Grows Bitcoin Holdings To 47,531 BTC

by Moussa
May 8, 2025
0

MARA Holdings, Inc. (NASDAQ: MARA) has reported first quarter 2025 earnings, announcing $213.9 million in revenue—a 30% increase from Q1...

Load More

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

© 2024 APPROX FOUNDATION - The Crypto Currency News