- Install
- Browser
- Config
- Database API
- Broadcast API
- Broadcast
- Auth
- Formatter
- Deprecated: Content
- Deprecated: Tags
- Deprecated: Follow API
- Deprecated: Votes
$ npm install viz-js-lib --save
Or
$ npm install git+https://github.com/VIZ-Blockchain/viz-js-lib.git --save
<script src="./viz.min.js"></script>
<script>
viz.api.getAccounts(['viz','in'], function(err, response){
console.log(err, response);
});
</script>
Default config should not work with VIZ without JSONRPC adress websocket in config. However you can change it to work with any viz fork as
viz.config.set('websocket','https://rpc.viz.lexai.host/'); // assuming JSONRPC transport is work at https://rpc.viz.lexai.host/
viz.config.set('address_prefix','VIZ');
viz.config.set('chain_id','2040effda178d4fffff5eab7a915d4019879f5205cc5392e4bcced2b6edda0cd');
viz.config.set('address_prefix','VIZ');
viz.config.get('chain_id');
viz.api.setSubscribeCallback(callback, clearFilter, function(err, result) {
console.log(err, result);
});
viz.api.setPendingTransactionCallback(cb, function(err, result) {
console.log(err, result);
});
viz.api.setBlockAppliedCallback(cb, function(err, result) {
console.log(err, result);
});
viz.api.cancelAllSubscriptions(function(err, result) {
console.log(err, result);
});
viz.api.getBlockHeader(blockNum, function(err, result) {
console.log(err, result);
});
viz.api.getBlock(blockNum, function(err, result) {
console.log(err, result);
});
viz.api.getState(path, function(err, result) {
console.log(err, result);
});
viz.api.getTrendingCategories(after, limit, function(err, result) {
console.log(err, result);
});
viz.api.getBestCategories(after, limit, function(err, result) {
console.log(err, result);
});
viz.api.getActiveCategories(after, limit, function(err, result) {
console.log(err, result);
});
viz.api.getRecentCategories(after, limit, function(err, result) {
console.log(err, result);
});
viz.api.getConfig(function(err, result) {
console.log(err, result);
});
viz.api.getDynamicGlobalProperties(function(err, result) {
console.log(err, result);
});
viz.api.getChainProperties(function(err, result) {
console.log(err, result);
});
viz.api.getHardforkVersion(function(err, result) {
console.log(err, result);
});
viz.api.getNextScheduledHardfork(function(err, result) {
console.log(err, result);
});
viz.api.getKeyReferences(key, function(err, result) {
console.log(err, result);
});
var publicKeys = ['VIZ...', 'VIZ...'];
viz.api.getKeyReferences(publicKeys, function(err, result) {
//console.log(err, result);
if (!err) {
result.forEach(function(item) {
console.log('getKeyReferences', 'username: [', item[0], ']');
});
}
else console.error(err);
});
viz.api.getAccounts(names, function(err, result) {
console.log(err, result);
});
var accounts=['viz','in'];
viz.api.getAccounts(accounts, function(err, result) {
//console.log(err, result);
if (!err) {
result.forEach(function(item) {
console.log('getAccounts', 'username: [', item.name, '] id: [', item.id, ']');
});
}
else console.error(err);
});
viz.api.lookupAccountNames(accountNames, function(err, result) {
console.log(err, result);
});
var usernames=['viz','in'];
viz.api.lookupAccountNames(usernames, function(err, result) {
//console.log(err, result);
if (!err) {
result.forEach(function(item) {
if (item) console.log('lookupAccountNames', 'username: [', item.name, '] id: [', item.id, ']');
else console.log('lookupAccountNames', 'account not found!');
});
}
else console.error(err);
});
viz.api.lookupAccounts(lowerBoundName, limit, function(err, result) {
console.log(err, result);
});
var searchAccountsQuery = 'vi';
var limitResults = 10;
viz.api.lookupAccounts(searchAccountsQuery, limitResults, function(err, result) {
//console.log(err, result);
if (!err) {
result.forEach(function(item) {
console.log('lookupAccounts', 'username: [', item, ']');
});
}
else console.error(err);
});
viz.api.getAccountCount(function(err, result) {
console.log(err, result);
});
viz.api.getConversionRequests(accountName, function(err, result) {
console.log(err, result);
});
viz.api.getAccountHistory(account, from, limit, function(err, result) {
console.log(err, result);
});
viz.api.getOwnerHistory(account, function(err, result) {
console.log(err, result);
});
viz.api.getRecoveryRequest(account, function(err, result) {
console.log(err, result);
});
viz.api.getAccountsOnSale(from, limit, function(err, result) {
console.log(err, result);
});
viz.api.getSubccountsOnSale(from, limit, function(err, result) {
console.log(err, result);
});
viz.api.getAccount(name, custom_protocol_id, function(err, result) {
console.log(err, result);
});
var account='on1x';
var custom_protocol_id='V';//Voice
viz.api.getAccount(account, custom_protocol_id, function(err, response) {
if (!err) {
console.log(response);
}
else {
console.error(err);
}
});
viz.api.getTransactionHex(trx, function(err, result) {
console.log(err, result);
});
viz.api.getTransaction(trxId, function(err, result) {
console.log(err, result);
});
viz.api.getRequiredSignatures(trx, availableKeys, function(err, result) {
console.log(err, result);
});
viz.api.getPotentialSignatures(trx, function(err, result) {
console.log(err, result);
});
viz.api.verifyAuthority(trx, function(err, result) {
console.log(err, result);
});
viz.api.verifyAccountAuthority(nameOrId, signers, function(err, result) {
console.log(err, result);
});
viz.api.getWitnesses(witnessIds, function(err, result) {
console.log(err, result);
});
viz.api.getWitnessByAccount(accountName, function(err, result) {
console.log(err, result);
});
viz.api.getWitnessesByVote(from, limit, function(err, result) {
console.log(err, result);
});
viz.api.lookupWitnessAccounts(lowerBoundName, limit, function(err, result) {
console.log(err, result);
});
viz.api.getWitnessCount(function(err, result) {
console.log(err, result);
});
viz.api.getActiveWitnesses(function(err, result) {
console.log(err, result);
});
viz.api.getMinerQueue(function(err, result) {
console.log(err, result);
});
var request_id=1;
var votes_limit=-1; //-1 all, 0 none, >0 limit
viz.api.getCommitteeRequest(request_id, votes_limit, function(err, result) {
console.log(err, result);
});
var request_id=1;
viz.api.getCommitteeRequestVotes(request_id, function(err, result) {
console.log(err, result);
});
var status=0;
viz.api.getCommitteeRequestsList(status, function(err, result) {
console.log(err, result);
});
var status=0;// active invites
viz.api.getInvitesList(status, function(err, result) {
console.log(err, result);
});
viz.api.getInviteById(id, function(err, result) {
console.log(err, result);
});
var key='VIZ77gW5bga9JEsT8Ke1A2RPUN2hyiNAnveB4D7phBDH3TBw1kzBg';
viz.api.getInviteByKey(key, function(err, result) {
console.log(err, result);
});
viz.api.getPaidSubscriptionOptions(account, function(err, result) {
console.log(err, result);
});
viz.api.getPaidSubscriptionStatus(subscriber, account, function(err, result) {
console.log(err, result);
});
viz.api.getActivePaidSubscriptions(subscriber, function(err, result) {
console.log(err, result);
});
viz.api.getInactivePaidSubscriptions(subscriber, function(err, result) {
console.log(err, result);
});
viz.api.getFollowers(following, startFollower, followType, limit, function(err, result) {
console.log(err, result);
});
/**
* getFollowers() returns subscribers
* @param {String} following - username whom return subscribers
* @param {String} startFollower - position from which item to return result
* @param {String} followType - subscription type, value: 'blog' or null
* @param {Integer} limit - how many records to return, the maximum value: 100
*/
var following = 'epexa';
var startFollower = '';
var followType = null;
var limit = 100;
viz.api.getFollowers(following, startFollower, followType, limit, function(err, result) {
//console.log(err, result);
if ( ! err) {
result.forEach(function(item) {
console.log('getFollowers', item);
});
}
else console.error(err);
});
viz.api.getFollowing(follower, startFollowing, followType, limit, function(err, result) {
console.log(err, result);
});
/**
* getFollowing() returns subscriptions
* @param {String} follower - username subscriber
* @param {String} startFollower - position from which item to return result
* @param {String} followType - subscription type, value: 'blog' или null
* @param {Integer} limit - how many records to return, the maximum value: 100
*/
var follower = 'epexa';
var startFollower = '';
var followType = null;
var limit = 100;
viz.api.getFollowing(follower, startFollower, followType, limit, function(err, result) {
//console.log(err, result);
if ( ! err) {
result.forEach(function(item) {
console.log('getFollowing', item);
});
}
else console.error(err);
});
viz.api.getFollowCount(account, function(err, result) {
console.log(err, result);
});
/**
* getFollowCount() returns count of subscribers and subscriptions
* @param {String} account - username of the user to return data
*/
var account = 'epexa';
viz.api.getFollowCount(account, function(err, result) {
console.log(err, result);
if (!err) {
console.log('getFollowCount', result);
}
else console.error(err);
});
viz.api.broadcastTransaction(trx, function(err, result) {
console.log(err, result);
});
viz.api.broadcastTransactionSynchronous(trx, function(err, result) {
console.log(err, result);
});
viz.api.broadcastBlock(b, function(err, result) {
console.log(err, result);
});
viz.api.broadcastTransactionWithCallback(confirmationCallback, trx, function(err, result) {
console.log(err, result);
});
viz.broadcast.committeeWorkerCreateRequest(wif, creator, url, worker, reward_amount_min, reward_amount_max, duration, function(err, result) {
console.log(err, result);
});
var wif='5K...';
var creator='on1x';
var url='https://goldvoice.club/...'; //URL with worker request for discussion
var worker='lightextension-escrow'; //account login for get payments from committee fund, it may be escrow with multisig
var reward_amount_min='1000.000 VIZ'; //Min amount of tokens needed for doing the work
var reward_amount_max='10000.000 VIZ'; //Targeted amount of tokens needed for doing the work (can not be greater that current committee fund)
var duration=432000; //60*60*24*5 - Request duration in sec (between COMMITTEE_MIN_DURATION=5 days and COMMITTEE_MAX_DURATION=30 days)
viz.broadcast.committeeWorkerCreateRequest(wif, creator, url, worker, reward_amount_min, reward_amount_max, duration, function(err, result) {
console.log(err, result);
});
viz.broadcast.committeeWorkerCancelRequest(wif, creator, request_id, function(err, result) {
console.log(err, result);
});
// vote_percent can be from -10000 to 10000
viz.broadcast.committeeVoteRequest(wif, voter, request_id, vote_percent, function(err, result) {
console.log(err, result);
});
viz.broadcast.createInvite(wif, creator, balance, invite_key, function(err, result) {
console.log(err, result);
});
// initiator can be temp account with any wif
viz.broadcast.claimInviteBalance(wif, initator, receiver, invite_secret, function(err, result) {
console.log(err, result);
});
// initiator can be temp account with any wif
// Using invite balance to receive shares
viz.broadcast.useInviteBalance(wif, initator, receiver, invite_secret, function(err, result) {
console.log(err, result);
});
viz.broadcast.inviteRegistration(wif, initator, new_account_name, invite_secret, new_account_key, function(err, result) {
console.log(err, result);
});
var levels=2;
var amount='5.000 VIZ';
var period=30;//days
var url='https://...';
viz.broadcast.setPaidSubscription(wif, account, url, levels, amount, period, function(err, result) {
console.log(err, result);
});
var levels=2;
var amount='5.000 VIZ';
var period=30;//days
var auto_renewal=true;
viz.broadcast.paidSubscribe(wif, subscriber, account, levels, amount, period, auto_renewal, function(err, result) {
console.log(err, result);
});
viz.broadcast.accountCreate(wif, fee, delegation, creator, newAccountName, master, active, regular, memoKey, jsonMetadata, referer, extensions, function(err, result) {
console.log(err, result);
});
/**
* accountCreate() new account registration
* @param {Base58} wif - private active key
* @param {String} fee - the cost of creating an account. It will be listed by virtue of the voice of the new account
* @param {String} creator - name of user who registers an account
* @param {String} newAccountName - new account username
* @param {Object} master - object containing a new master key
* @param {Object} active - object containing a active key
* @param {Object} regular - object containing a regular key
* @param {String} memoKey - new memo key
* @param {String} jsonMetadata - additional data for a new account (avatar, location, etc.)
* @param {String} referer - name of a referer user, can be empty
*/
var wif = '5K...';
var fee = '10.000 VIZ';
var delegation = '0.000000 SHARES';
var creator = 'viz';
var newAccountName = name;
var master = {
weight_threshold: 1,
account_auths: [],
key_auths: [[newKeys.masterPubkey, 1]]
};
var active = {
weight_threshold: 1,
account_auths: [],
key_auths: [[newKeys.activePubkey, 1]]
};
var regular = {
weight_threshold: 1,
account_auths: [],
key_auths: [[newKeys.regularPubkey, 1]]
};
var memoKey = newKeys.memo;
var jsonMetadata = '{}';
var referer = '';
var extensions = [];
viz.broadcast.accountCreate(wif, fee, delegation, creator, newAccountName, master, active, regular, memoKey, jsonMetadata, referer, extensions, function(err, result) {
//console.log(err, result);
if (!err) {
console.log('accountCreate', result);
}
else console.error(err);
});
viz.broadcast.delegateVestingShares(wif, delegator, delegatee, vesting_shares, function(err, result) {
console.log(err, result);
});
viz.broadcast.accountUpdate(wif, account, master, active, regular, memoKey, jsonMetadata, function(err, result) {
console.log(err, result);
});
/**
* @param {Base58} wif - private master key
* @param {String} accountName - account username
* @param {Object} master - object containing a new master key
* @param {Object} active - object containing a active key
* @param {Object} regular - object containing a regular key
* @param {String} memoKey - new memo key
* @param {String} jsonMetadata - additional data for a new account (avatar, location, etc.)
*/
var accountName = name;
var masterWif = '5J...'
var master = {
weight_threshold: 1,
account_auths: [],
key_auths: [[newKeys.masterPubkey, 1]]
};
var active = {
weight_threshold: 1,
account_auths: [],
key_auths: [[newKeys.activePubkey, 1]]
};
var regular = {
weight_threshold: 1,
account_auths: [],
key_auths: [[newKeys.regularPubkey, 1]]
};
var memoKey = newKeys.memo;
var jsonMetadata = account.json_metadata;
viz.broadcast.accountUpdate(masterWif, account, master, active, regular, memoKey, json_met, function(err, result)
{
if (!err)
{
console.log(viz.auth.getPrivateKeys(name, password, roles));
} else {
console.log('Error accountUpdate: ');
console.log(err);
}
});
viz.broadcast.accountWitnessProxy(wif, account, proxy, function(err, result) {
console.log(err, result);
});
viz.broadcast.accountWitnessVote(wif, account, witness, approve, function(err, result) {
console.log(err, result);
});
viz.broadcast.changeRecoveryAccount(wif, accountToRecover, newRecoveryAccount, extensions, function(err, result) {
console.log(err, result);
});
viz.broadcast.custom(wif, requiredAuths, requiredRegularAuths, id, json, function(err, result) {
console.log(err, result);
});
viz.broadcast.escrowDispute(wif, from, to, agent, who, escrowId, function(err, result) {
console.log(err, result);
});
viz.broadcast.escrowRelease(wif, from, to, agent, who, receiver, escrowId, Amount, function(err, result) {
console.log(err, result);
});
viz.broadcast.escrowTransfer(wif, from, to, Amount,escrowId, agent, fee, jsonMeta, ratificationDeadline, escrowExpiration, function(err, result) {
console.log(err, result);
});
viz.broadcast.fillVestingWithdraw(wif, fromAccount, toAccount, withdrawn, deposited, function(err, result) {
console.log(err, result);
});
viz.broadcast.recoverAccount(wif, accountToRecover, newMasterAuthority, recentMasterAuthority, extensions, function(err, result) {
console.log(err, result);
});
viz.broadcast.requestAccountRecovery(wif, recoveryAccount, accountToRecover, newMasterAuthority, extensions, function(err, result) {
console.log(err, result);
});
viz.broadcast.escrowApprove(wif, from, to, agent, who, escrowId, approve, function(err, result) {
console.log(err, result);
});
viz.broadcast.setWithdrawVestingRoute(wif, fromAccount, toAccount, percent, autoVest, function(err, result) {
console.log(err, result);
});
viz.broadcast.transfer(wif, from, to, amount, memo, function(err, result) {
console.log(err, result);
});
/**
* transfer() transfer VIZ
* @param {Base58} wif - private master key
* @param {String} from - username who send, whose master key
* @param {String} to - username who get
* @param {String} amount - number of coins in the format: 0.001 VIZ
* @param {String} memo - a content
*/
var wif = '5J...';
var from = 'epexa';
var to = 'melnikaite';
var amount = '0.001 VIZ';
var memo = 'gift';
viz.broadcast.transfer(wif, from, to, amount, memo, function(err, result) {
//console.log(err, result);
if (!err) {
console.log('transfer', result);
}
else console.error(err);
});
viz.broadcast.transferToVesting(wif, from, to, amount, function(err, result) {
console.log(err, result);
});
viz.broadcast.withdrawVesting(wif, account, vestingShares, function(err, result) {
console.log(err, result);
});
viz.broadcast.witnessUpdate(wif, owner, url, blockSigningKey, function(err, result) {
console.log(err, result);
});
let chain_properties = {
account_creation_fee:"1.000 VIZ",
create_account_delegation_ratio:10,
create_account_delegation_time:2592000,
maximum_block_size:131072,
min_delegation:"0.001 VIZ",
min_curation_percent:0,
max_curation_percent:10000,
bandwidth_reserve_percent:1000,
bandwidth_reserve_below:"500.000000 SHARES",
flag_energy_additional_cost:0,
vote_accounting_min_rshares:500000,
committee_request_approve_min_percent:1000,
};
viz.broadcast.chainPropertiesUpdate(wif, owner, chain_properties, function(err, result) {
console.log(err, result);
});
var chain_properties_init = {
account_creation_fee:"1.000 VIZ",
create_account_delegation_ratio:10,
create_account_delegation_time:2592000,
maximum_block_size:131072,
min_delegation:"0.001 VIZ",
min_curation_percent:0,//deprecated
max_curation_percent:10000,//deprecated
bandwidth_reserve_percent:1000,
bandwidth_reserve_below:"500.000000 SHARES",
flag_energy_additional_cost:0,//deprecated
vote_accounting_min_rshares:500000,
committee_request_approve_min_percent:1000,
};
var chain_properties_hf4=chain_properties_init;
chain_properties_hf4.inflation_witness_percent=2000;
chain_properties_hf4.inflation_ratio_committee_vs_reward_fund=5000;
chain_properties_hf4.inflation_recalc_period=2000;
var chain_properties_hf6=chain_properties_hf4;
chain_properties_hf6.data_operations_cost_additional_bandwidth=0;
chain_properties_hf6.witness_miss_penalty_percent=10;
chain_properties_hf6.witness_miss_penalty_duration=86400;
var chain_properties_hf9=chain_properties_hf6;
chain_properties_hf9.create_invite_min_balance="10.000 VIZ";
chain_properties_hf9.committee_create_request_fee="100.000 VIZ";
chain_properties_hf9.create_paid_subscription_fee="100.000 VIZ";
chain_properties_hf9.account_on_sale_fee="10.000 VIZ";
chain_properties_hf9.subaccount_on_sale_fee="100.000 VIZ";
chain_properties_hf9.witness_declaration_fee="10.000 VIZ";
chain_properties_hf9.withdraw_intervals=28;
viz.broadcast.versionedChainPropertiesUpdate(wif, owner, [3,chain_properties_hf9], function(err, result) {
console.log(err, result);
});
viz.broadcast.fillVestingWithdraw(wif, fromAccount, toAccount, withdrawn, deposited, function(err, result) {
console.log(err, result);
});
var receiver='committee';
var energy=2;//0.02%
var custom_sequence=0;
var memo='Hello';
var beneficiaries=[]
viz.broadcast.award(wif,initiator,receiver,energy,custom_sequence,memo,beneficiaries,function(err,result){
console.log(err,result)
});
var price='100.000 VIZ';
var on_sale=true;
viz.broadcast.setAccountPrice(master_wif,account_owner,account_seller,price,on_sale,function(err,result){
console.log(err,result)
});
var price='100.000 VIZ';
var on_sale=true;
viz.broadcast.setSubaccountPrice(master_wif,account_owner,subaccount_seller,price,on_sale,function(err,result){
console.log(err,result)
});
var price='100.000 VIZ';
var token_to_shares='1.000 VIZ';//minimum account creation fee, will be converted in SHARES
var new_authority_key='VIZ6qHF4v41yNf1nEyyzMFK9iC6uMs4fQVbj2e76iBhjZXFUaQiiz';
viz.broadcast.buyAccount(active_wif,buyer_login,account_or_subaccount_to_buy,offer_price,new_authority_key,token_to_shares,function(err,result){
console.log(err,result)
});
viz.auth.verify(name, password, auths);
var username = 'epexa';
var password = 'P5...'; // master password
// object in which the key type public key (active, memo, master, regular), and the value of the array in the array itself is the public key
var auths = {
regular: [['VIZ...']]
};
var verifyResult = viz.auth.verify(username, password, auths);
console.log('verify', verifyResult);
viz.auth.generateKeys(name, password, roles);
/**
* generateKeys() generating new keys for a new account
* @param {String} name - new account username
* @param {String} password - master-password for a new account
*/
var name = 'epexa4';
var password = 'qwerty12345';
var newKeys = viz.auth.generateKeys(name, password, ['master', 'active', 'regular', 'memo']);
console.log('newKeys', newKeys);
viz.auth.getPrivateKeys(name, password, roles);
var username = 'epexa';
var password = 'P5H...'; // master password
var roles = ['master', 'active', 'regular', 'memo']; // optional parameter, if not specify, then all keys will return
var keys = viz.auth.getPrivateKeys(username, password, roles);
console.log('getPrivateKeys', keys);
viz.auth.isWif(privWif);
var privWif = '5J...';
var resultIsWif = viz.auth.isWif(privWif);
console.log('isWif', resultIsWif);
viz.auth.toWif(name, password, role);
var username = 'epexa';
var password = 'P5H...'; // master password
var role = 'regular'; // private key type, one of master, active, regular, memo
var privateKey = viz.auth.toWif(username, password, role);
console.log('toWif', privateKey);
viz.auth.wifIsValid(privWif, pubWif);
var privWif = '5J...'; // private key
var pubWif = 'VIZ...'; // public key
var resultWifIsValid = viz.auth.wifIsValid(privWif, pubWif);
console.log('wifIsValid', resultWifIsValid);
viz.auth.wifToPublic(privWif);
var privWif = '5J...'; // private key
var resultWifToPublic = viz.auth.wifToPublic(privWif, pubWif);
console.log('wifToPublic', resultWifToPublic);
// you can set debug to true for see in console transaction, raw transaction in hex and signature in hex
viz.auth.signTransaction(trx, keys, debug);
var password = viz.formatter.createSuggestedPassword();
console.log(password);
// => 'GAz3GYFvvQvgm7t2fQmwMDuXEzDqTzn9'
var parentAuthor = 'ned';
var parentPermlink = 'a-selfie';
var contentPermlink = viz.formatter.contentPermlink(parentAuthor, parentPermlink);
console.log(contentPermlink);
// => 're-ned-a-selfie-20170621t080403765z'
var VIZPower = viz.formatter.estimateAccountValue(account);
var shares = viz.formatter.sharesToVIZ(vestingShares, totalVestingShares, totalVestingFund);
console.log(shares);
var isValidUsername = viz.utils.validateAccountName('test1234');
console.log(isValidUsername);
// => 'null'
var isValidUsername = viz.utils.validateAccountName('a1');
console.log(isValidUsername);
// => 'Account name should be longer.'
//wif,account,text,reply,share,beneficiaries,loop,callback
viz.utils.voiceText('5K...','on1x','Just a test from viz-js-lib',false,false,false,false,function(result){console.log(result)});
### Add Voice Event
//get last V/Voice custom protocol block sequencer from account viz.api.getAccount(account,'V',function(err,result){ if(!err){ let object={ 'p':previous, 'e':event_type, 'b':target_block,//block to hide, edit or append 'd':{//new data for edited object 't':'Just a SECOND test from viz-js-lib', } }; let new_data=JSON.stringify(object);
//wif,account,event_type,target_account,target_block,data,loop,callback
//event_type: h - hide, e - edit, a - append
viz.utils.voiceText('5K...','on1x','e','on1x',result.custom_sequence_block_num,new_data,false,false,false,false,function(result){console.log(result)});
} });
//wif,account,passphrase,comment,text,reply,share,beneficiaries,loop,callback
let passphrase='decode me :)';
let comment='You see a bottle labeled, "decode me :)"';
viz.utils.voiceEncodedText('5K...','on1x',passphrase,comment,'Just a test from viz-js-lib',false,false,false,false,function(result){console.log(result)});
//wif,account,passphrase,comment,text,reply,share,beneficiaries,loop,callback
let passphrase=['test1','pass2','password3'];
let comment=['Do your 1 test','Type your 2 pass','Enter your 3 password'];
viz.utils.voiceEncodedText('5K...','on1x',passphrase,comment,'Just a test from viz-js-lib',false,false,false,false,function(result){console.log(result)});
//wif,account,text,reply,share,beneficiaries,loop,callback
let wif='5K...';
let account='on1x';
let markdown=`Well, Voice protocol markdown have **bold**, __italic__, ~~stroke~~ and \`code\`
## Headers 2
### And 3
Also we got:
> Quotes and
>> Second style for citation
Support lists:
* Unordered
* as ordinary
* items
And ordered, ofc:
*n Yes
*n it is!
After all, simple images:

Paragraph
with
multiline
...and #en #example tags support :)`;
//wif,account,title,markdown,description,image,reply,share,beneficiaries,loop,callback
viz.utils.voicePublication(wif,account,'Test publication from viz-js-lib',markdown,false,false,false,false,false,false,function(result){console.log(result)});
/*
//encoded publication work same way as text
let passphrase='decode me :)';
let comment='You see a bottle labeled, "decode me :)"';
viz.utils.voiceEncodedPublication(wif,account,passphrase,comment,'Test publication from viz-js-lib',markdown,false,false,false,false,false,false,function(result){console.log(result)});
*/
viz.api.getContent(author, permlink, votes_count, function(err, result) {
console.log(err, result);
});
/**
* getContent() receiving a post
* @param {String} author - author of the post
* @param {String} permlink - url-address of the post
* @param {Integer} votes_count - use -1 for showing all votes
*/
var author = 'viz';
var permlink = 'test';
viz.api.getContent(author, permlink, -1, function(err, result) {
//console.log(err, result);
if (!err) {
console.log('getContent', result.title);
}
else console.error(err);
});
viz.api.getContentReplies(parent, parentPermlink, function(err, result) {
console.log(err, result);
});
/**
* getContentReplies() receiving a contents
* @param {String} parent - author of the post
* @param {String} parentPermlink - url-address of the post
*/
var parent = 'epexa';
var parentPermlink = 'test-url';
viz.api.getContentReplies(parent, parentPermlink, function(err, result) {
//console.log(err, result);
if (!err) {
result.forEach(function(item) {
console.log('getContentReplies', item.body);
});
}
else console.error(err);
});
viz.api.getDiscussionsByAuthorBeforeDate(author, startPermlink, beforeDate, limit, function(err, result) {
console.log(err, result);
});
viz.api.getRepliesByLastUpdate(startAuthor, startPermlink, limit, function(err, result) {
console.log(err, result);
});
viz.api.getTrendingTags(afterTag, limit, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByTrending(query, function(err, result) {
console.log(err, result);
});
/**
* getDiscussionsByTrending() receiving posts by tags
* @param {Object} query - A search object that includes tags and a limit or authors username and url-address of post
*/
var query = {
select_tags: ['dev', 'test'],
limit: 100,
//start_author: 'epexa',
//start_permlink: 'test-url'
};
viz.api.getDiscussionsByTrending(query, function(err, result) {
//console.log(err, result);
if (!err) {
result.forEach(function(item) {
console.log('getDiscussionsByTrending', item.title);
});
}
else console.error(err);
});
viz.api.getDiscussionsByCreated(query, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByActive(query, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByCashout(query, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByPayout(query, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByVotes(query, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByChildren(query, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByHot(query, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByFeed(query, function(err, result) {
console.log(err, result);
});
viz.api.getDiscussionsByBlog(query, function(err, result) {
console.log(err, result);
});
/**
* getDiscussionsByBlog() receiving posts by author and tag
* @param {Object} query - search object that includes the author, tag, limit
*/
var query = {
select_authors: ['epexa'],
select_tags: ['dev'],
limit: 100
};
viz.api.getDiscussionsByBlog(query, function(err, result) {
//console.log(err, result);
if (!err) {
result.forEach(function(item) {
console.log('getDiscussionsByBlog', item.title);
});
}
else console.error(err);
});
viz.api.getDiscussionsByContents(query, function(err, result) {
console.log(err, result);
});
viz.api.getActiveVotes(author, permlink, function(err, result) {
console.log(err, result);
});
viz.api.getAccountVotes(voter, function(err, result) {
console.log(err, result);
});
// deprecated
viz.broadcast.content(wif, parentAuthor, parentPermlink, author, permlink, title, body, curation_percent, jsonMetadata, extensions, function(err, result) {
console.log(err, result);
});
/**
* content() add a post
* @param {Base58} wif - private regular key
* @param {String} parentAuthor - for add a post, empty field
* @param {String} parentPermlink - main tag
* @param {String} author - author of the post
* @param {String} permlink - url-address of the post
* @param {String} title - header of the post
* @param {String} body - text of the post
* @param {String} jsonMetadata - meta-data of the post (images etc.)
* @param {Array} extensions - example: [[ 0, {"beneficiaries":[{"account":"viz","weight":2000},{"account":"on1x","weight":1000}]} ]]
*/
var wif = '5K...';
var parentAuthor = '';
var parentPermlink = 'dev';
var author = 'epexa';
var permlink = 'test-url';
var title = 'test';
var body = 'test2';
var curation_percent = 5000;//50%
var jsonMetadata = '{}';
var extensions = [];
viz.broadcast.content(wif, parentAuthor, parentPermlink, author, permlink, title, body, curation_percent, jsonMetadata, extensions, function(err, result) {
//console.log(err, result);
if (!err) {
console.log('content', result);
}
else console.error(err);
});
/**
* content() add a content
* @param {Base58} wif - private regular key
* @param {String} parentAuthor - for add a content, author of the post
* @param {String} parentPermlink - for add a content, url-address of the post
* @param {String} author - author of the content
* @param {String} permlink - unique url-address of the content
* @param {String} title - for create a content, empty field
* @param {String} body - text of the content
* @param {String} jsonMetadata - meta-data of the post (images etc.)
*/
var wif = '5K...';
var parentAuthor = 'epexa';
var parentPermlink = 'test-url';
var author = 'epexa';
var permlink = 're-' + parentAuthor + '-' + parentPermlink + '-' + Date.now(); // re-epexa-test-url-1517333064308
var title = '';
var body = 'hi!';
var curation_percent = 5000;//50%
var jsonMetadata = '{}';
viz.broadcast.content(wif, parentAuthor, parentPermlink, author, permlink, title, body, curation_percent, jsonMetadata, extensions, function(err, result) {
//console.log(err, result);
if (!err) {
console.log('content', result);
}
else console.error(err);
});
viz.broadcast.contentReward(wif, author, permlink, Payout, vestingPayout, function(err, result) {
console.log(err, result);
});
// deprecated
viz.broadcast.deleteContent(wif, author, permlink, function(err, result) {
console.log(err, result);
});
// deprecated
viz.broadcast.vote(wif, voter, author, permlink, weight, function(err, result) {
console.log(err, result);
});