0

As I understand, all the front-end components for a react based ethereum dapp are rendered from the point of view of the user's metamask default account. All the calls to constant functions in solidity to retrieve state variable values and render the relevant components to display to users, uses the user's account.

What I would like is to add a certain design to it:

  1. an automated routine running in background (with no front-end components to display) which will assess the state variable value and execute a smart contract transaction only meant to be executed by owner.

  2. This owner based transaction invocation routine needs to run perpetually in the background, in an automated fashion, and not just when there is a user having your website page opened in his/her browser.

As an example, in case of the voting dapp, I want to build a routine where once a certain number of votes have been put, or a certain time limit expired, the vote calculation routine should be executed automatically, and that too from the owner's address (since only owner has the privilege of counting votes and declaring winner).

Could you please elaborate how such routine can be implemented? Would I have to store the owner's keystore file at the server end for it? is it a safe strategy? Thanks.

0

You could have a program running in the same server that serves the webpage of your app. This program will read the state of your variables and react to it executing functions. As this runs in your pc you can do the transactions using the owner keys in a safe manner.

If the trigger is solely based on time, meaning that you want the a function to be executed after a certain time has passed or in general at a particular date you can use services like AION Scheduling system. Because Aion creates an independent account (smart contract) for each user you can be sure that if the function comes from that address it correspond to a function scheduled by the owner. AION can call any function you indicate when a particular time or block has arrived.

Hope this helps

  • this is much help Jaime. Also since I've purchased a domain for it, and perhaps will be using a hosting space, would it be possible to store the keystore safely in this hosting space and prevent the keystore from being retrieved? Where exactly in the web server (hosting space) should i store the keystore and the automated routine and is there a way i can encrypt them ? Thanks. – Kombo Jan 30 at 8:16
  • If the server of your webpage is not under your control, then you shouldn't store the key, you can just run your own server (or maybe an instance in Google or Amazon) and run your program there. I am doing this currently, I have a python script running in 3 servers () attending the changes in variables in a smart contract. – Jaime Jan 30 at 9:53
  • understood. i control the domain and credentials to a shared hosting space. what i want to know is, would I have to create the said automated routine using a server side scripting like node.js with express ? is there any kind of example available in the net so that i could refer and get a complete idea ? – Kombo Jan 30 at 10:45
  • any platform will work, node, python etc, note that this program that monitors the smart contract doesn't need to be related to your website, the app does its normal functioning and your script reads the smart contract, not the web code that runs the app. As for examples, any web3js or web3py tutorial should do. Let me know if I am missing something. – Jaime Jan 30 at 11:03
0

You need to reevaluate.

Here's the constraint. A client can't sign for an address without knowledge of the private key. Impersonation is not possible. msg.sender doesn't lie.

You need to consider the process and doing so will possibly influence the contract design.

If only the owner can declare a winner, that implies that there is a client or server out there that will eventually do so. That style implies reintroduction of centralization that often isnt necessary.

If the deadline for voting has passed and the votes are counted honestly then there would be nothing subjective for the owner to decide. It's similar for auctions and games.

Now, there might be some code to run at the conclusion. You need to think about who will run it or what triggers it. Its common to let the winner run such a function since they are incentivized to pay for gas.

Consider

function claimPrize () public onlyWinner onlyIfClosed ... 

Hope it helps.

  • I dont think ethereum dapps can be 100% decentralized in every scenario. There are certain aspects that sometimes HAS to be controlled by an owner account only. for example, in case of voting system having time-specific windows for registration, voting and completion, at present is there any other option of building this design other than an automated bot closing the voting window after a certain time and executing vote calculation ? – Kombo Jan 30 at 2:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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