0

I currently have a setup with two docker containers. The first container, peerA, has a private ethereum network running a single node. The second container, web-app, has a web application that uses web3.js with the hope of interfacing with the private network in the first container.

Right now, I've managed to successfully get a connection from the first container to the second but have run into some issues with RPC.

The first container was run with the following commands:-

docker run -it --name peerA -v /opt/docker/ethereum:/root/.ethereum -p 30310:30310 -p 50000:50000 --network testnet docker-testnet --datadir ./peerA --networkid 4567 --port 50000 --rpc --rpcport 30310 --rpccorsdomain "*" --rpcapi "eth,web3,net,admin,miner,personal" --rpcvhosts "*" --ipcpath ./peerA

which opens an RPC endpoint at: http://peerA(or 127.0.0.1):30310

Both containers are running on a docker network "testnet", so I obtained a connection in the web-app container with web3.js using the first containers name:-

const web3 = new Web3(new Web3.providers.HttpProvider("http://peerA:30310"));

This gives me a web3 instance which I successfully use to get access to a smart contract deployed on the private network. The issue now is, attempting to call functions on the contract object results in the following errors:-

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://peerA:30310/. (Reason: CORS request did not succeed)

followed by:

Unhandled promise rejection Error: "Invalid JSON RPC response: """

Which leads me to believe that there might be an issue with the --rpccorsdomain "*" flag.

I would greatly appreciate any assistance in resolving this error or even a better way of handling a web-app + private network docker setup.

0

try to append this to your command: --rpcaddr "0.0.0.0"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.