2

I have a DApp that uses metamask or mist as a provider. The DApp can read some info from the contract and show it on page using mist or metamask. Is it possible to read contract and show information without using metamask or mist?

I think I have a few options: 1) Run a node on a dedicated server and just open default localhost:8545 to use it as a provider. But there will be a lot of security issues then... 2) Maybe use some public nodes like infura.io or blackapps.net(?)

I just want to know the right way to do it. Thank you.

4

You can run the ethereum node on a dedicated server as you mentioned but rather than opening port 8545 and talk to it directly, Create a nodeJS API server on that instance(which will use web3.js) and talk to that nodejs server instead.

NodeJS server will communicate to Ethereum node with the help of web3.js APIs, which will make your design secure and ethereum node will not be accessible from outside.

Hope this helps.

  • So if there is a provider like meta or mist, I should just use them. Then if there is no provider, I should just send HTTP requests to my NodeJS server, right? I didn't really work with backend, so sorry if I got something wrong. One more question: in my contract there are functions that can be run by owner address only. Does it mean that if I want users get some info via my owner account I should add new functions, so they didn't get more info than they should? Or I just need to deploy contract from one account and then use another one to use it in nodejs server? Thank you anyway! – porfavorite Jul 9 '17 at 8:52
  • NodeJS will work as a middleware and there has to be a provider in a background for your DApp to work and your DApp's UI shall talk to NodeJS server through HTTP requests as you mentioned. – Sanchit Jul 9 '17 at 9:47
  • You don't need to deploy another contract. You can create another modifier like OnlyMember, which will not have owner privileges but would be able to access some information which you want them to access. – Sanchit Jul 9 '17 at 9:51
  • I implemented OnlyMember modifier in one of the contracts I wrote, you can take a look for the reference - github.com/inovizz/lms/blob/master/contracts/LMS.sol – Sanchit Jul 9 '17 at 9:52
  • thanks, but I meant that if I use nodejs server that interacts with the ethereum node using my deploying account, that means that all HTTP requests to the nodejs server will be processed by this server using my 'owner' contract, which means the msg.sender will be owner and the onlyMember modifier doesn't make much sense. That's why I asked maybe somehow I should use another contract on my ethereum node, not which I used to deploy the contract. – porfavorite Jul 9 '17 at 10:29
0

While it may go against the "Ethos" of the community, we have found that it is much easier to use a Node as a Service provider such as Infura or Alchemy. Having to manage your own node can be a headache with Ethereum forks and managing bugs in Parity/Geth.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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