'orderer client failed to connect to localhost:10050: failed to create new connection: connection

I am learning Hyperledger Fabric. I have added an org to my application channel. I successfully joined the channel and I am trying to invoke the chaincode. I am receiving the error: Error: error getting broadcast client: orderer client failed to connect to localhost:10050: failed to create new connection: connection error: desc = "transport: error while dialing: dial tcp 127.0.0.1:10050: connect: connection refused"

when I run chaincodeInvoke function:

The content of the function is:

 # Create Car
peer chaincode invoke -o localhost:10050 \
    --ordererTLSHostnameOverride orderer4.example.com \
    --tls $CORE_PEER_TLS_ENABLED \
    --cafile $ORDERER_CA \
    -C $CHANNEL_NAME -n ${CC_NAME} \
    --peerAddresses localhost:7051 \
    --tlsRootCertFiles $PEER0_ORG1_CA \
    --peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
    -c '{"function": "createCar","Args":["Car-1111", "Audi", "R8", "Red", "Pavan"]}'

Thank you for your help



Solution 1:[1]

Be sure that your orderer is really running on port 10050. Do a docker ps to check the port number for the container. I presume that you are running docker if you are following the tutorials.

I will also presume that you ran these commands to install the contract code

peer lifecycle chaincode install
peer lifecycle chaincode approveformyorg   for both peers
peer lifecycle chaincode commit

If the contract code was installed, there should be other containers listed in your docker ps command to show that they exist.

In my experience, this kind of error has been due to misconfiguration i.e. using an incorrect port number to that defined in the YAML file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1