0

I've set successfully a private Ethereum network by Geth and now I need to deploy contracts there. I use web3.js for interacting to the network and use each Geth node as the web3 provider for each system that Geth node is installed on there. But, BTW no deployment occurred and no block mined. However, when I set the web3 provider to ws://127.0.0.1:8545 (For checking the provider) it works and deployment and block mining are successful done. I think it's because of setting the Geth node as web3 provider but I don't know what the exact problem is.

The deployment code in NodeJS by web3.js:

const Web3=require("web3");
const fs=require("fs");
const web3=new Web3(new Web3.providers.WebsocketProvider("ws://<Geth ip in the private network>:<port>"));
      web3.eth.personal.unlockAccount(<sender address>,<password>,300);
const contractJson=".../contract.json";
const contractObj=JSON.parse(fs.readFileSync(contractJsonInterface));
const contractBytecode=`...`;
const contract=new web3.eth.Contract(contractObj.abi,null,{data:contractBytecode});
      contract.deploy().send({from:<sender address>}).then((ins)=>{console.log("Contract mined at "+ins.options.address);});

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.