I am creating a project where i need to use my smart contract to add data to the storage but in a programatically delayed way:

I am using web3 in my nodejs server, and i want to create the transaction as usually, using web3 but delay or halt the transaction broadcast until I want to send it.

My idea is to get the raw transaction and save it in an off-chain database as the string it is. then when I want to broadcast the transaction I can get it from the database and use web3 to send it as a raw transaction.

So first i want to know if my idea is achievable, and is there anyway i can save transactions inside my node instead and then send them programatically because the idea of saving transactions in relational databases is not really appealing and seems unsecure.

  • Please understand that your node runs an internal database itself that is no less or more secure than any other database. Apr 19 '18 at 15:11
  • ok, i got that. how is that going to affect the way i store the transaction. Apr 19 '18 at 15:13

What you describe is feasible. You would have software clients form transactions, sign, and then your server would record their signed actions in your database for possible submission to the network at a later time.

It occurs to me that you'll have some extra considerations at the app level. For example, users would likely resist the idea unless things are arranged with definate expiry times along the lines of "good until block number n". That expiry should probably be enforced at the smart contract level to severely limit what can be done by the privileged server.

There won't be a double-spend issue but there is certainly the possibility of being over-extended in which case transactions will fail.

Have a look at 0x protocol for something that works along these lines.

Hope it helps.

  • how would a not broadcasted transaction overextend ? is there a time on the validity of a transaction before it is recognized by the network ? Apr 19 '18 at 16:26
  • Not what I meant. A person could write cheques for more funds or another resource than they really have. The premise here is such transactions are not being submitted to the network to find out. If there is a presumption that the "server" will somehow check, I think that will be very hard to enforce without writing something to the chain, which you are clearly trying to avoid. Apr 19 '18 at 16:39

Ethereum doesn't support "transaction delay" feature you are describing.

But ...

It is a bad idea to sign transactions and leave them (in raw format) off chain waiting for submission. Because a transaction includes nonce field, which is a consecutive number which belongs to your account. This is why your first transaction will be blocking all the following transactions. You will have to store pending transactions without signing them, and only when you really need to execute them, you would sign and send them to the blockchain.

Raw transactions are perfectly safe to be stored anywhere, in fact, they are stored in the blockchain database right now and everybody has access to them, it's public info.

  • So the best idea is to create the transaction in raw form and not sign it. then do the signing later ( so signing adds the nonce to the transaction ) Apr 20 '18 at 7:34
  • raw means they are already signed
    – Nulik
    Apr 20 '18 at 13:59
  • so can i create a transaction and store it in my database then sign it and send it to the network ? Apr 20 '18 at 14:28
  • @KakiMasterOfTime exactly, you sign before you send it to the network
    – Nulik
    Apr 20 '18 at 15:50

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.