I am trying to deploy the contract using web3.js@1.2.6
i have mentioned the error and code that i have typed i m stuck in line 10
-
Gee, you couldn't think of a better way than taking a photo of your screen with a camera??? I can see the background of your room there. A screenshot is just one simpler option, which is also not reccommended here, since users cannot copy/paste parts of your code into their answers. A copy/paste of your code into the question is the preferred way for posting questions here. Please do so. – goodvibration Feb 28 '20 at 10:21
-
var Web3 = require('web3') var web3 = new Web3(new Web3.providers.HttpProvider("localhost:8545")); web3.eth.accounts code = fs.readFileSync('blockchain/voting.sol').toString() solc = require('solc') compiledCode = solc.compile(code) abiDefinition = JSON.parse(compiledCode.contracts[':Voting'].interface) VotingContract = web3.eth.contract(abiDefinition) – Kaarthiga Ayyappan Feb 28 '20 at 10:56
-
This is d code i m trying and it gives error – Kaarthiga Ayyappan Feb 28 '20 at 10:57
-
Downvoted, pictures are not searchable, please add code. – DRP Feb 28 '20 at 14:03
-
github.com/amand1996/Votechain – Kaarthiga Ayyappan Feb 28 '20 at 14:21
Obviously, I didn't replicate the code. You should try to upload code blocks that would allow us to replicate your code fast.
Nevertheless, my guess is that the error on you line 10 is caused because of web3.eth.Contract(...) expecting 2 arguments, ABI and Address of Contract, and you just gave it the ABI. Check the documentation and the following example they have here. Also, the function Contract is with a capital 'C'. Hope that helps
-
1
-
2Check this web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html#deploy – João Quintanilha Feb 28 '20 at 11:26
-
1I don't think you're supposed to know the address of the contract you're deploying. You only need the address along with the ABI if you're trying to interact with an already deployed contract with web3. – NYC Tech Engineer Feb 29 '20 at 1:21
In web3.js v0.x, use web3.eth.contract
.
In web3.js v1.x, use new web3.eth.Contract
.
-
I have used it still it gives as web3.eth.contract is not a function – Kaarthiga Ayyappan Feb 28 '20 at 10:48
-
-
@KaarthigaAyyappan: Good. So you can use the second option, as suggested in my answer. – goodvibration Feb 28 '20 at 12:26