IOTA Proof of Work: Remote Vs Local explained

Phani
Bytes
Published in
2 min readJan 14, 2019

A proof of work is a piece of data which is difficult (costly, time-consuming) to produce but easy for others to verify and which satisfies certain requirements.

The purpose of Proof of Work is to prevent spam. IOTA ledger is secured by a heavily distributed form of CCurl Proof of Work. The IoT devices create signed transactions and compute a Proof of Work in a distributed fashion.

Without going in-depth of an IOTA transaction mechanics, we will see how a transaction is created to understand where PoW comes into play. To create a transaction:

First, we construct a transaction bundle. The bundle groups together all the individual transactions which relate to a single intent of value transfer. The constructed bundle is signed with your private keys.

Second, we randomly choose two previous unapproved transactions, or tips to approve. This will allow us to join the Tangle. We can get two tips from IRI via getTransactionsToApprove.

Third, is Proof of Work(PoW). To join Tangle every transaction in the bundle requires a nonce. The nonce is the result of PoW.

The Proof of Work can be done on the device locally or it can be delegated to external devices.

Local Proof of Work — Using CCurl WebGL2 implementation

const IOTA = require('iota.lib.js')
const curl = require('curl.lib.js')
const iota = new IOTA({ provider: 'http://localhost:14265' })curl.overrideAttachToTangle(iota.api)
curl.init()

Remote Proof of Work — Delegate to a 3rd party PoW service

const { composeAPI } = require('@iota/core')async function attachToTangle(
trunkTransaction, branchTransaction, mWM, trytes, cb
) {
//3rd Party PoW
const resp = await makeRequestToPoWService(...);
if ((resp[0]) != null) {
return resp[0]
} else {
return resp[1].trytes
}
}
const iota = composeAPI({
provider: 'http://localhost:14265',
attachToTangle
})

If you are using IOTA.js (version ≥ 1.x.x) this library will come handy: https://github.com/pasupulaphani/iota.js-remote-pow

The library has 2 providers to choose from. ATM it supports

For older IOTA.js (version <1.x.x) please use the iota.lib.js.powsrvio.

Happy coding!

--

--