How do I send the proof of work to a node that is executed on a client?
Do I use "attachToTangle" and for branch and trunk transactions do I just use the hashed transaction with the nonce?
Iota Stack Exchange is a question and answer site for users of Iota, the open-source cryptocurrency for IoT that does not use a blockchain. It only takes a minute to sign up.
Sign up to join this communityYou use getTransactionsToApprove
to get the two transactions/tips that you need to use in your PoW. Then you must craft your transaction trytes, the Javascript libraries help with this. Then you include the two transactions, your trytes, and few other parameters as input for the cCurl program. This program can be run on the command line (C# program) or via Javascript. It will output your transaction trytes, combined with the nonce (It's all in trytes). You send these trytes to the public node/API via broadcastTransaction
. And that how the client does the PoW!
Here are the links for cCurl and for javascript cCurl interface:
To understand how this works, you have to take a look at how transactions are generated: https://learn.iota.org/faq/what-is-needed-to-make-a-transaction
I'm assuming you use a light node.
Signing: The transaction is constructed and validated using your private key. This is done locally on your PC.
Tip selection: You ask a full node to give you two tips to reference and therefore validate them.
Proof of work: In most cases, this is done on your side, for three reasons:
A: Nodes are already busy handling transactions. Having to do the proof of work would probably break them and create a backlog.
B: In most cases, Nodes are not rewarded in any way. They are keeping up the tangle for free by propagating transactions, choosing tips for light nodes and getting their neighbours up to date if they aren't.
C: The POW is done to prevent spam attacks to the network. If a node would allow it for free, someone could just spam it.
There are a few outliers, but not many. So you just broadcast the whole transaction (with nonce) to the network (needn't be the node you received the tips from). Any node will accept the transaction, given that it is valid and not directly or indirectly validating an invalid transaction. So there is no need to send the POW, just send the whole transaction one you have completed the POW
attachToTangle
will ask the node to do PoW; how to do it on client side depends on the client library (javascript, java, ...)branch
andtrunk
you have to ask forgetTransactionsToApprove
.