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,370 points
3,951 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
• 69,220 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,370 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,400 points
904 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,100 points

edited Aug 10, 2018 by Omkar 2,845 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,100 points
815 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
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
+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,610 points
1,414 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 7, 2018 in Blockchain by Christine
• 15,790 points
5,727 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 18, 2018 in Blockchain by sapan
1,162 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP