0

I'm working on making a contract that will issue a user a token. The user will perform an action and this will be stored in our database. Once it's stored in our database, there should be a link between our database and the contract/dapp that triggers it to issue the token. I was wondering how one would go about creating that link. Is it as easy as making a listener(if possible)?

1

It would help if you told us a bit more about what you're trying to achieve - why is your data split between the blockchain and your database? (I'm not saying this is the wrong thing to do, but the appropriate design will depend on your goals.)

As you're describing it you're going to end up with two different actions, one putting the data in the database and the other issuing the token on the blockchain. One of these may succeed and the other fail, so you'll probably want to designate one as the "master" and the other as the "slave" - ie, one always holds the ultimate version of the data, and the other is updated afterwards to match it.

If you consider the blockchain to be the "master", the obvious thing to do is to make the transaction by sending a request to your contract on the blockchain, then have that issue an event. Then have a process listening for that event and putting the necessary data in your database. If something falls over you'll be able to rerun that process and catch up with any events that it's missing, although your database is going to be behind in the meantime.

  • Its split because the database is for our company, so we can store the data the user puts in. The contract portion is for voting rights on donating money. So what will happen is the user would use our service and each time they do, we store the data from the transaction in our database. Afterwards the idea is to also give the user each time the service is used. The tokens are used as voting rights to decide how we donate a portion of our revenue. So i would say our database would have to be the master and the contract be the slave, and thats where my question arises. Hopefully this clarifies. – EtherNewb Jul 1 '16 at 18:14
  • OK, so add a field to the database with the timestamp of the successful token issuance tx. Insert, send the tx to your contract. Include the ID from your database as a parameter to the contract. In your contract keep track of that ID and return if it's already been handled. Otherwise, issue the token and raise an event with the ID of the record in the db. Run a process to listen for those record ID events and update the database timestamp so you know it's done. Run a process to check for database records whose transactions failed and send the transaction to the blockchain. – Edmund Edgar Jul 1 '16 at 22:34
  • So let me just run an example to see if i got it right. The user uses our service, and once they do its sent to the database. The database will then send a timestamp and id to the contract. Check to see that the id match and timestamps are different. Then issue them a token and return the tx or token number to the database and complete the contract. I hope I'm understanding that. So i have another question how would one go about setting up that sort of link from database to contract. Would i code it in the database to connect to the contract using an address or vice versa? Hope that's clear. – EtherNewb Jul 5 '16 at 16:55
  • The obvious way to do this would be to run a daemon process, probably written in node.js, to talk to both the blockchain and the database. – Edmund Edgar Jul 5 '16 at 21:56
  • And just to understand the options, If i make the contract the master, how would you go about that, if there are any specifics to it. For example, on our end, i would write up the contract in the wallet and deploy it. Once deployed, when our user uses our product we give them a unique code and that should be lead to the contract. The contract receives the code, finds or makes the user, and issues them a token. Then it pings the database to update and that should be done. Is that roughly the jist of it, or am i off? Is there a specific way to do this and would i still need a daemon process? – EtherNewb Jul 7 '16 at 15:39

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.