Last active
June 22, 2018 08:42
-
-
Save tonsmets/0466a5d648aa4dafae3564dc85231109 to your computer and use it in GitHub Desktop.
Basic IOTA transaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import the IOTA library. | |
// Install with this command: 'npm install iota.lib.js' | |
var IOTA = require('iota.lib.js'); | |
// Create IOTA instance directly with Node (provider) | |
// This is node is your entry point to the Tangle | |
var iota = new IOTA({ | |
'provider': 'https://balancer.iotatoken.nl:4433/' | |
}); | |
// A seed is used as your 'private key' so never share it! | |
const seed = 'PRIVATE9PRIVATE9PRIVATE9PRIVATE9PRIVATE9PRIVATE9PRIVATE9PRIVATE9PRIVATE9PRIVATE99'; // KEEP IT SECURE!! | |
// Create a message to attach to your transaction | |
// and convert it to Trytes (data format used by IOTA) | |
let message = 'By the way, you can also check addresses and hashes in realtime on https://thetangle.org/'; | |
let messageTrytes = iota.utils.toTrytes(message); | |
// The receiving address | |
let address = 'JHXINEABYNFJUZFAEC9CEGTIOKXQIO9ULUI9OOZMTEATF9DOWHZLQIVNQJWTOBSAY9PTLYQTCMTAXPDTZYPAL9VGAD'; | |
// Construct the transfer bundle with address, | |
// value (amount of IOTA), a tag and a message | |
var transfer = [{ | |
'address': address, | |
'value': 0, | |
'tag': 'INFINIOTA', | |
'message': messageTrytes, | |
}]; | |
// Send transfer to the Tangle. Depending on the Node config of the connected Node | |
// you also do the PoW at this point. The magic numbers can stay there for the Mainnet | |
iota.api.sendTransfer(seed, 9, 14, transfer, function(e, bundle) { | |
if (e) throw e; | |
console.log("Successfully sent your transfer: ", bundle); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment