git clone https://github.com/creativechain/trantor-lib-nodejs.git
cd trantor-lib-nodejs
npm install
Maybe npm install
will fail installing sqlite3,
if so check this issue to see if it fixes your error
You need to have creativechain core running to use this library. You can download the binaries for your platform from here
You need to create a creativecoin.conf in creativecoins core datadir, and add:
rpcuser=creativecoin
rpcpassword=creativecoin
txindex=1
reindex-chainstate=1
Then run the core with the datadir specified.
-
node ./lib/trantor-lib.js <command> [args]
-
Commands
explore
: explore creativechain blockchain and indexes transactions and content.- Quite slow
getData <txid>
#works: returns data from transactiongetTx <txid>
#works: returns transaction informationlistUnspent <address>
#works: returns list of unspent transactions for specified addressnewWallet
#works: creates a new address with private keygetWallets
#works: return all wallets savedsend <target_address> <amount> <fee>
: creates and sends amount to target_addresssaveData <amount> <fee> '<json_string>'
: saves json data in blockchainseedFile <filepath>
: starts seeding torrentgetTorrent <magnet_uri> <save_path>
: downloads a torrent from magnet_uri and saves it to save_path
- Require trantor into your project.
const trantor = require('./trantor-lib-nodejs/lib/trantor-lib');
- Methods
trantor.newWallet(cback)
#works: creates a new address with private key- cback(newWallet) newWallet = { wif: "wif", address: "address" }
trantor.getWallets(cback)
#works: returns all wallets saved- cback(addresses) addresses = [ { wif: "wif", address: "address" }, ... ]
trantor.explore(cback)
#works: explore creativechain blockchain and indexes transactions and content.- cback() will be called when explore finishes
- Quite slow
trantor.listUnspent(addr, cback)
#works: returns list of unspent transactions for specified addresstrantor.findWord(word, page, cback)
: returns references for transactions containing a wordtrantor.smartdeal(datos)
: not testedtrantor.creadeal(data, datos, cback)
: not testedtrantor.findaddr(addr)
: #not tested - finds entries for address in dbtrantor.getcontracts(type, ref, cback)
: gets contracts for type and reference
trantor.pushTx(rawtx, cback)
#works: pushes rawtx to creativechain blockchaintrantor.decodeRawTransaction(rawtx, cback)
: returns decoded transaction from raw transactiontrantor.getDecodedTransaction(txid, cback)
: returns return transaction informationtrantor.send(addr, amount, fee, cback)
: creates a raw transaction and sends itaddr
string: the address to send toamount
number: the amount to sendfee
number: the fee of the txcback
function: called when tx has been sent, and its called with the transaction id
trantor.saveData(amount, fee, data, cback)
: saves json data in blockchainamount
number: the amount to sendfee
number: the fee of the txdata
json string: the data to save in blockchaincback
function: called when tx has been sent, and its called with the new transaction idtrantor.getData(txid, cback)
#works: returns data from transaction - Data saved from saveData
trantor.seedFile(filepath, cback)
: starts seeding file, and calls cback with a Torrent Object- Then you can save the magnetURI to the blockchain
- ie:
const trantor = require('./trantor-lib-nodejs/lib/trantor-lib'); trantor.seedFile('/images/test.png', function(torrent){ let data = { title: "my cool image", magnetUncompressed: torrent.magnetURI, description: "Some image from google" } trantor.saveData(0.002, 0.002, JSON.stringify(data), function (response) { if (!response.error) { console.log(response.error); } else { console.log("transaction sent correctly: txid ["+response+"]"); } }); })
trantor.getTorrent(magnetURI, savePath, cback)
: download a torrent from magnetURI and saves it to savePath, cback is called with Torrent Object- ie:
const trantor = require('./trantor-lib-nodejs/lib/trantor-lib'); let magnetURI = '...'; trantor.getTorrent(magnetURI, '/torrents', function(torrent){ torrent.files.forEach(function (file) { console.log("File arribed", file); }) })
Vicent Nos Ripolles, Manolo Edge