Wednesday, November 27, 2024
HomeBitcoinbitcoin core - Utilizing sendtoaddress is failing utilizing json-rpc and I do...

bitcoin core – Utilizing sendtoaddress is failing utilizing json-rpc and I do not know why


The steps i adopted are i first load the pockets in a special methodology which works, then i examine the stability of the pockets in a special methodology which works, after which I name this sendbitcoin methodology(under). I can see that the bitcoind server will get the message however it returns with a 500.

If i exploit bitcoin-cli it really works nevertheless i want so as to add a -rpcwallet flag. It is my understanding that because the pockets has been loaded i should not want to make use of flag. My wallets aren’t encrypted so i do not imagine i want to make use of a passphrase.

My bitcoin.conf file appears 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 tactic appears like.

func (w *Pockets) SendBitcoin(sendTo string, quantity 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 setting variables are usually not set")
    return BitcoinTransaction{}, errors.New("RPC_USER, RPC_PASSWORD, or BITCOIN_NODE_HOST setting variables are usually not set")
}

// Put together the RPC request payload
requestBody := map[string]interface{}{
    "jsonrpc": "1.0",
    "methodology":  "sendtoaddress",
    "params":  []interface{}{sendTo, quantity},
    "id":      1,
}

logrus.Printf("request physique : %v", requestBody)
logrus.Printf("Sending on pockets %v", w.Identify)

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

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

shopper := &http.Shopper{}

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

req.SetBasicAuth(username, password)
req.Header.Set("Content material-Sort", "software/json")

// Ship HTTP request
resp, err := shopper.Do(req)
if err != nil {
    log.Errorf("did not ship HTTP request: %v", err)
    return BitcoinTransaction{}, fmt.Errorf("did not ship HTTP request: %v", err)
}
//...

logs

[00] bitcoin      | 2024-02-22T22:36:59Z [rpc] ThreadRPCServer 
 methodology=loadwallet consumer=rpcuser
[00] rest-server  | time="2024-02-22T22:36:59Z" stage=data msg="stability 
= 0.0003933699999999999, quantity = 0.0001"
[00] bitcoin      | 2024-02-22T22:36:59Z Utilizing SQLite Model 3.38.5
[00] bitcoin      | 2024-02-22T22:36:59Z Utilizing pockets 
 /house/bitcoin/.bitcoin/testnet3/wallets/111-20240221
[00] bitcoin      | 2024-02-22T22:36:59Z [rpc] ThreadRPCServer 
methodology=sendtoaddress consumer=rpcuser
[00] rest-server  | time="2024-02-22T22:36:59Z" stage=data msg="request 
 physique : map[id:1 jsonrpc:1.0 method:sendtoaddress params: 
[tb1qljunwv4hv8nx3mwsrup4fse5zhahyjtmx0fwzl 0.0001 ]]"
[00] rest-server  | time="2024-02-22T22:37:00Z" stage=data 
msg="surprising standing code: 500"

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments