Skip to content

Instantly share code, notes, and snippets.

@pasupulaphani
Created October 30, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasupulaphani/e22048046bd893f19678ec9595595b6d to your computer and use it in GitHub Desktop.
Save pasupulaphani/e22048046bd893f19678ec9595595b6d to your computer and use it in GitHub Desktop.
new IOTA NodeJs API (1.0.0-beta.5) transaction example
const { composeAPI } = require('@iota/core') //1.0.0-beta.5
const { asciiToTrytes } = require('@iota/converter') //1.0.0-beta.5
const iota = composeAPI({
provider: 'https://nodes.devnet.iota.org:443'
})
async function makeTx(seed, address) {
const transfers = [{
address: address,
value: 1,
tag: asciiToTrytes('node-tx'),
message: asciiToTrytes('Hello World!')
}]
const minWeightMagnitude = 9 //devnet
const depth = 3
// bundle prep for all transfers
const trytes = await iota.prepareTransfers(seed, transfers)
const bundle = await iota.sendTrytes(trytes, depth, minWeightMagnitude)
console.log(`Published transaction with tail hash: ${bundle[0].hash}`)
console.log(`Explorer link: https://devnet.thetangle.org/transaction/${bundle[0].hash}`)
}
const senderSeed = '<seed>'
const addressTo = '<address>'
makeTx(senderSeed, addressTo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment