How do I interact with a smart contract on a private network through web3.js

0 votes

I have deployed my smart contract on private network using mist and geth. Following is my script:

if (typeof web3 !== 'undefined') {
            web3 = new Web3(web3.currentProvider);
        } else {
            // set the provider you want from Web3.providers
            web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
        }
web3.eth.defaultAccount = web3.eth.accounts[0];
var CoursetroContract = web3.eth.contract(YOUR ABI);

var Coursetro = CoursetroContract.at('PASTE CONTRACT ADDRESS HERE');
console.log(Coursetro);

Now, how do i interact with smart contracts using Web3.js?

Aug 17, 2018 in Blockchain by sabby
• 4,350 points
189 views

2 answers to this question.

0 votes

The web3.eth.Contract object makes it easy to interact with smart contracts on the ethereum blockchain. When you create a new contract object you give it the json interface of the respective smart contract and web3 will auto convert all calls into low level ABI calls over RPC for you.

To know more, visit: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html

answered Aug 17, 2018 by Omkar
• 67,120 points
0 votes
I found a blog that explains how you can do this. I am sharing the link to the blog. Hope it helps:

https://medium.com/@amkurian/interacting-with-ethereum-smart-contracts-through-web3-js-e0efad17977
answered Aug 20, 2018 by slayer
• 29,050 points

Related Questions In Blockchain

0 votes
1 answer
+1 vote
1 answer

How can I initiate a transaction on ethereum private network using mobile device?

There is no android wallet to connect ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,330 points
41 views
0 votes
1 answer

How can I deploy a HelloWorld contract on my testrpc network?

The problem lies in the command: truffle migrate Your truffle migrate command ...READ MORE

answered Apr 27, 2018 in Blockchain by Perry
• 17,010 points

edited Aug 10, 2018 by Omkar 410 views
+1 vote
1 answer

How can nodes interact with a Smart Contract?

If you are using Remix IDE to ...READ MORE

answered Apr 27, 2018 in Blockchain by Perry
• 17,010 points
24 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
105 views
0 votes
1 answer
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,620 points
119 views
+3 votes
4 answers

How do I add a new node on a Hyperledger network?

You can do this by generating the crypto ...READ MORE

answered Apr 6, 2018 in Blockchain by Christine
• 15,790 points
1,399 views
+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 17, 2018 in Blockchain by sapan
45 views