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

0
20


The steps i adopted are i first load the pockets in a special methodology which works, then i verify 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 but it surely returns with a 500.

If i take advantage of bitcoin-cli it really works nonetheless 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 seems to be 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 strategy seems to be 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 surroundings variables will not be set")
    return BitcoinTransaction{}, errors.New("RPC_USER, RPC_PASSWORD, or BITCOIN_NODE_HOST surroundings variables will not be 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("didn't marshal JSON request: %v", err)
    return BitcoinTransaction{}, fmt.Errorf("didn't marshal JSON request: %v", err)
}

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

consumer := &http.Shopper{}

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

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

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

logs

[00] bitcoin      | 2024-02-22T22:36:59Z [rpc] ThreadRPCServer 
 methodology=loadwallet person=rpcuser
[00] rest-server  | time="2024-02-22T22:36:59Z" stage=information 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 
 /residence/bitcoin/.bitcoin/testnet3/wallets/111-20240221
[00] bitcoin      | 2024-02-22T22:36:59Z [rpc] ThreadRPCServer 
methodology=sendtoaddress person=rpcuser
[00] rest-server  | time="2024-02-22T22:36:59Z" stage=information 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=information 
msg="sudden standing code: 500"

LEAVE A REPLY

Please enter your comment!
Please enter your name here