btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.2k stars 2.36k forks source link

unexpected EOF when loading rpc.cert #1967

Closed lenhatquang97 closed 1 year ago

lenhatquang97 commented 1 year ago

Hello everyone, I have connected to btcd and I try to run this part of code for connecting to server:

func LoadCerts() ([]byte, error) {
    certHomeDir := btcutil.AppDataDir("btcd", false)
    certs, err := ioutil.ReadFile(filepath.Join(certHomeDir, "rpc.cert"))
    if err != nil {
        return nil, err
    }
    return certs, nil
}

certs, _ := LoadCerts()
client, err := rpcclient.New(&rpcclient.ConnConfig{
    Host:         "127.0.0.1:8334",
    User:         opt.User,
    Pass:         opt.pass,
    Certificates: certs,
}, nil)

However, when I run this code, it always says "unexpected EOF". What is the main problem with this code? I have learned this code in an example in docs/json_rpc_api.md.

Roasbeef commented 1 year ago

You'll get that if you either can't connect, or there's no cert file, or it isn't formatted correctly. Try to use either print statement or a debugger like dlv to figure out where things are going wrong.