The post Syscoin + Node.js = Blockchain Apps! appeared first on Justin Silver.
]]>You will need to have syscoind
or Syscoin Core Qt running on your system and have node
/npm
installed. If you don’t have Node.js I recommend installing it via nvm
.
First make sure that syscoind
is configured so that you can connect to the RPC server locally. Use the example below, choosing a secret rcpuser
, rpcpassword
, and optionally changing the rpcport
. You will need to use these values later to connect to query the blockchain using Node.js later.
You don’t really need the ZMQ config for this example, but it shows how to tell Syscoin to listen on those ports should you want to implement a Node.js ZMQ client in your application :).
Before making changes be sure to stop Syscoin by running syscoin-cli stop
, update the configuration, then run syscoind
to start the process again. If you change the config file before stopping Syscoin it will prevent syscoin-cli
from being able to communicate with the RPC server properly. Changing the index values may require you to restart with syscoind -reindex
.
# server server=1 daemon=1 # indexes addressindex=1 txindex=1 litemode=0 # rpc rpcuser=u rpcpassword=p rpcport=8370 rpcallowip=127.0.0.1 # zmq listener config zmqpubaliasrecord=tcp://127.0.0.1:3030 zmqpubaliashistory=tcp://127.0.0.1:3030 zmqpubaliastxhistory=tcp://127.0.0.1:3030 zmqpubassetrecord=tcp://127.0.0.1:3030 zmqpubassetallocation=tcp://127.0.0.1:3030 zmqpubassethistory=tcp://127.0.0.1:3030 zmqpubcertrecord=tcp://127.0.0.1:3030 zmqpubcerthistory=tcp://127.0.0.1:3030 zmqpubescrowrecord=tcp://127.0.0.1:3030 zmqpubescrowbid=tcp://127.0.0.1:3030 zmqpubescrowfeedback=tcp://127.0.0.1:3030 zmqpubofferrecord=tcp://127.0.0.1:3030 zmqpubofferhistory=tcp://127.0.0.1:3030 zmqpubhashblock=tcp://127.0.0.1:3030 zmqpubhashtx=tcp://127.0.0.1:3030 zmqpubhashtxlock=tcp://127.0.0.1:3030 zmqpubrawblock=tcp://127.0.0.1:3030 zmqpubrawtx=tcp://127.0.0.1:3030 zmqpubrawtxlock=tcp://127.0.0.1:3030
Next create a new folder for your project and create a Node project by running npm init
and answering the questions as you see fit. The only module that is required is syscoin-core
, a cutting edge version can be found at my fork.
mkdir -p my-syscoin-app && cd my-syscoin-app npm init # answer init questions npm install -S https://github.com/doublesharp/syscoin-core.git#dev-3.0
Once syscoin-core
is installed you can use the following example to get started. Make sure that the port
, username
, and password
match the values set in your syscoin.conf
file.
const SyscoinClient = require('@syscoin/syscoin-core'); const syscoin = new SyscoinClient({ host: process.env.SYSCOIND_HOST || 'localhost', port: process.env.SYSCOIND_PORT || 8370, username: process.env.SYSCOIND_USER || 'u', password: process.env.SYSCOIND_PASS || 'p', timeout: 30000, }); async function run() { // prune expired data! const pruneStart = Date.now(); const prune = await syscoin.pruneSyscoinServices(); console.log('pruned', prune, 'in', Date.now()-pruneStart, 'ms'); // get all alias records const aliasStart = Date.now(); const list = await syscoin.listAliases(0); console.log('fetched', list.length, 'aliases in', Date.now()-aliasStart, 'ms'); // get just an array of alias names const aliases = list.map((alias) => alias._id); // ...etc process.exit(0); } run();
> node index.js pruned { services_cleaned: 0 } in 341 ms fetched 15162 aliases in 1685 ms
You can take this same basic structure and turn it into an Express app, etc, depending on the needs of your application. It’s surprisingly easy to get started building blockchain applications with Syscoin!
The post Syscoin + Node.js = Blockchain Apps! appeared first on Justin Silver.
]]>The post Syscoin 3 Alias Creation appeared first on Justin Silver.
]]>Before we start – please read this post fully! It will only take a few minutes, and you will feel much more comfortable creating your alias. Don’t worry about all the text, I included a lot of detail but these are the only commands you actually need to run – it’s mostly cutting and pasting.
aliasnew YOUR_ALIAS "" 3 EXPIRATION YOUR_ALIAS_ADDRESS "" "" "" syscointxfund ALIAS_HEX '{"addresses": ["YOUR_FUNDING_ADDRESS"]}' signrawtransaction RAW_HEX syscoinsendrawtransaction SIGNED_HEX
To use any Syscoin Alias service you will first need to enable the address index in the Syscoin Core by adding addressindex=1
to your syscoin.conf
file, then restarting Syscoin Core Qt and reindexing (it will prompt you when you restart). If you are using syscoind
directly you will need to run syscoin-cli stop
followed by syscoind -reindex
to trigger the reindexing process.
The process to create a Syscoin Alias is just 4 commands. You will need to run them once to reserve your alias, then a second time after waiting for a block confirmation to finalize your alias registration. You will need a small amount of SYS available, and either an existing address (funded or unfunded) or a new address to assign to the alias.
When selecting an expiration timestamp you will need to use Unix Epoch Time. Determine your expiration time by using a site such as https://www.epochconverter.com/ and make sure to only select 1 or 2 years for your expiration – aliases become exponentially more expensive and be quite pricey to reserve for a very long time.
If you’re wallet is encrypted (and it should be!) then you will need to unlock you wallet with `walletpassphrase ‘YOUR_PASSSPHRASE’ 1800` to unlock it for 30 minutes (1800 seconds).
It is recommended to create a new address to use to fund your alias creation transaction – you can do this by sending 1 SYS to a new address in your wallet and noting the address for later use when funding your alias creation transaction.
First, get familiar with the aliasnew command. You can read the help below or run syscoin-cli help aliasnew
to see it on your system.
aliasnew [aliasname] [public value] [accept_transfers_flags=3] [expire_timestamp] [address] [encryption_privatekey] [encryption_publickey] [witness] <aliasname> alias name. <public value> alias public profile data, 256 characters max. <accept_transfers_flags> 0 for none, 1 for accepting certificate transfers, 2 for accepting asset transfers and 3 for all. Default is 3. <expire_timestamp> Time in seconds. Future time when to expire alias. It is exponentially more expensive per year, calculation is FEERATE*(2.88^years). FEERATE is the dynamic satoshi per byte fee set in the rate peg alias used for this alias. Defaults to 1 hour. <address> Address for this alias. <encryption_privatekey> Encrypted private key used for encryption/decryption of private data related to this alias. Should be encrypted to publickey. <encryption_publickey> Public key used for encryption/decryption of private data related to this alias. <witness> Witness alias name that will sign for web-of-trust notarization of this transaction.
If you are running these commands from the command line and not the Syscoin Core Qt Console, just add “syscoin-cli” before each command, otherwise follow them filling in your details where there are capital letters.
In these examples YOUR_ALIAS
is the alias name you want to register, in lower case (ironically). Replace YOUR_ALIAS_ADDRESS
with the address you want to associate with your alias (possibly your masternode staking address?). For the EXPIRATION
use https://www.epochconverter.com/ to generate the expiration in Unix Epoch time – no more than a year or two is strongly recommend due to exponentially increasing fees.
aliasnew YOUR_ALIAS "" 3 EXPIRATION YOUR_ALIAS_ADDRESS "" "" ""
[ "00740000010ae45894ba90b24c5120db9354d44fc93f17b86dcc269eddd8111f2454c629f20200000000feffffff02f1020000000000005e515140313463626631663365313533636633656166643736346530396262303532373239336134343935353934333936363536323665353436656533633531316364646d7576a91464c63b4b3398452a32a8d9f47b42ee63d2a59cac88ac85c2e59a000000001976a914c1da47e228637af983e1c75172506eabd77962c188acf4040000", "TKA43ch9qBVh7H8LmfSNFN5GqPsXfLyNqJ" ]
Copy the hex string result from the aliasnew
command (the top part), which we will call ALIAS_HEX
below to keep it readable. Replace YOUR_FUNDING_ADDRESS
with the address you want to fund the transaction with – note that the change from this transaction will be sent to a new address, so it’s best to fund with a different address than you want to have your SYS associated with.
ALIAS_HEX
=output from aliasnew, “0074000….” in the example aboveYOUR_FUNDING_ADDRESS
=address to fund txsyscointxfund ALIAS_HEX '{"addresses": ["YOUR_FUNDING_ADDRESS"]}'
[ "007400000179347c7191687ee50469bb8cb8a50a978db51651f482e114d24a6ba926a027ed010000001976a914572b8c4219a138984742c46b231f63afaad6688c88acffffffff02b80b0000000000005e515140373137383831646139346264353934343335383837363766373739343538386134373966313064613163373862313235373333623664373165386262623666326d7576a9149ec5c7b6544d752575ed7672d7984b5aceb14cd588ac534c0609000000001976a9147dc19cec3f574a85d94f2b05186bf3fec39f170588ac00000000" ]
The result of this command is the raw transaction hex, which we will call RAW_HEX
from now on, again for brevity. Next you need to sign this raw transaction with your private key before it can be submitted.
RAW_HEX
=output from syscointxfundsignrawtransaction RAW_HEX
{ "hex": "00740000010ae45894ba90b24c5120db9354d44fc93f17b86dcc269eddd8111f2454c629f2020000006a47304402200be0e27776d44cb9ce69dc683c5d1fc41aceca4131392957181f25d40eae186b02201ac64cdbd219f6e587f347d87f5f72f36a22a85050a8c4d79e0d9e3adb29eff9012103d0f289fbb510b953fa5cecc20cf70f95a249c6e30cc8fec292b45a0637120a19feffffff02f1020000000000005e515140313463626631663365313533636633656166643736346530396262303532373239336134343935353934333936363536323665353436656533633531316364646d7576a91464c63b4b3398452a32a8d9f47b42ee63d2a59cac88ac85c2e59a000000001976a914c1da47e228637af983e1c75172506eabd77962c188acf4040000", "complete": true }
This gives us a signed transaction hex that we can submit to the network which we will call SIGNED_HEX
. Now, submit it to the network to reserve your alias.
SIGNED_HEX
=output from signrawtransactionsyscoinsendrawtransaction SIGNED_HEX
{ "txid": "d4a5ecdd111978082862f2b2ebc199f29158dd5f397df3117dd68e791ed9f446" }
The result of this is the transaction id that was submitted to the network. Now we need to wait for a couple of blocks before we can confirm the alias reservation to complete the registration. Check the current block height so you know where to start.
> getinfo
{ "version": "3.0.4.1", "dashversion": "0.12.3", "protocolversion": 70221, "walletversion": 3000000, "balance": 26.42070085, "privatesend_balance": 0.00000000, "blocks": 36817, "timeoffset": 0, "connections": 8, "proxy": "", "difficulty": 137061451496.0324, "testnet": false, "keypoololdest": 1525736009, "keypoolsize": 1999, "unlocked_until": 0, "paytxfee": 0.00000000, "relayfee": 0.00010000, "errors": "" }
In the results you can see "blocks": 36817,
though it will be higher when you run these commands :). Wait for a minute or two, then run it again to check the height. After a couple of blocks you are ready to continue. Enter the same four commands again entering exactly the same information for aliasnew
but updating each with the response of the commands the second time you run them.
aliasnew YOUR_ALIAS "" 3 EXPIRATION YOUR_ALIAS_ADDRESS "" "" "" syscointxfund ALIAS_HEX '{"addresses": ["YOUR_FUNDING_ADDRESS"]}' signrawtransaction RAW_HEX syscoinsendrawtransaction SIGNED_HEX
Now you’re done! You can check the status of your alias with the following commands. Fund your alias by sending to either your alias name or the underlying address.
aliasinfo YOUR_ALIAS aliasbalance YOUR_ALIAS
The post Syscoin 3 Alias Creation appeared first on Justin Silver.
]]>