Primas sdk for Node env
npm install primas-sdk-nodejs --save
Node.js >= 8.0.0 required.
You should have keystore in your workspace. As an alternative, you can provide the keystore option in the constructor config. All numbers are treated as big number, you should use bignumber.js to deal with it.
- Primas-nodejs-sdk
- Install
- Compatibility
- Prerequisite
- Summary
- Basic Usage
- Metadata Sign
- Create A Primas Instance
- Operations
- Account
- .metadata(params, callback)
- .addressMetadata(address, callback)
- .create(params)
- .update(accountId, params)
- .credits(params, callback)
- .contents(params, callback)
- .groups(params, callback)
- .shares(params, callback)
- .sharesInGroup(params, callback)
- .likes(params, callback)
- .comments(params, callback)
- .groupApplications(params, callback)
- .shareApplications(params, callback)
- .reports(params, callback)
- .notifications(params, callback)
- .avatar(params, callback)
- .avatarImg(params, callback)
- .addressMetadata(address, callback)
- .joinedGroups(params, callback)
- Token
- Content
- Content Interaction
- .shares(params, callback)
- .groupShares(params, callback)
- .reports(params, callback)
- .createReport(shareId, params)
- .likes(params, callback)
- .createLike(shareId, params)
- .cancelLike(shareId, likeId, params)
- .comments(params, callback)
- .replys(params, callback)
- .createComment(shareId, params)
- .updateComment(shareId, commentId, params)
- .cancelComment(shareId, commentId, params)
- Group
- .group(params, callback)
- .create(params)
- .create(groupId, params)
- .dismiss(groupId, params)
- .members(params, callback)
- .join(groupId, params)
- .approveOrDecline(groupId, groupMemberId, params)
- .quit(groupId, groupMemberId, params)
- .whitelist(params, callback)
- .createWhitelist(groupId, params)
- .approveOrDeclineWhitelist(groupId, whitelistId, params)
- .quitWhitelist(groupId, whitelistId, params)
- .shares(params, callback)
- .createShare(groupId, params)
- .approveOrDeclineShare(shareId, params)
- .cancelShare(shareId, params)
- .avatar(params, callback)
- .avatarImg(params, callback)
- Node
- Query
- System
- Timeline
- Account
- Known Errors
All operation use nodejs callback. All api is async function.
for example:
var Primas = require('primas-sdk-nodejs');
var client = new Primas({
address: "<Your address>",
passphrase: "<Your password>"
})
client.Account.metadata({accountId: '<account id>'}, function (err, res) {
if (err) {
// handle error
return;
}
// handle res
})
// for method without callback, you should explicitly call send after sign
var account = client.Account.create(
{
name: "<account name>",
creator: {
account_id: "<root account id>", // The platform ID we received in the previous step.
sub_account_id: "<user id on the platform>" // This id is used together to identify the user on Primas network.
},
extra: {
hash: "<a hex string>" // In case of sensitive user data that needs proof-of-existence, the data hash can be stored here.
}
}
);
account.send(function(err, res) {
if (err) {
// handle error
return;
}
// For sub accounts. No account id is returned at the moment.
// The sub account is identified user root account id and user id on the platform.
// console.log(res.id);
console.log(res.dna);
})
if you place a folder named "keystore" in your project or you pass a keystore option in constructor, this sdk will use the build-in signer to sign metadata. for production usage, you should implement a Primas Offline Signer instead of the build-in signer. for example:
// here we pass the passphrase and use the build-in signer
var client = new Primas({
address: "<Your address>",
passphrase: "<Your password>",
node: "https://rigel-a.primas.network"
});
var account = client.Account.create(
{
name: "<account name>",
// avatar: "", // Avatar should be a metadata ID which can only be uploaded after the account creation.
address: "<account address>"
});
// if your have keystore in your workspace, just send
account.send(function(err, res) {
if (err) {
// handle error
return;
}
// The response contains the account id and metadata dna
})
// here we don't pass the passphrase because the signer you should implement on your self
var client = new Primas({
address: "<Your address>",
node: "https://rigel-a.primas.network"
});
var account = client.Account.create({
name: "<account name>",
// avatar: "", // Avatar should be a metadata ID which can only be uploaded after the account creation.
address: "<account address>"
});
var dataJson = account.getRawMetadata();
// do sign now, this sign method is your own offline signer exposed
var signature = sign(dataJson); // this will return signature
// after sign
account.setSignature(signature);
// then send, like the above
account.send(...);
use Primas constructor to create instance.
options:
- node [string] node url
- address {string} your address with '0x' prefix
- passphrase [string] your passphrase, if not provide, you shoud use signer on your own
- keystorePath [string] you can specify the dir of your keystore
- keystore [string] the keystore string or object
- json [boolean] use application/json or not
example:
var Primas = require('primas-sdk-nodejs');
var client = new Primas({
address: "<Your address>",
passphrase: "<Your password>",
keystore: "key store object or string" // if this option is not provide, sdk will find keystore in the workspace
})
all the callback parameter is a standard nodejs async callback function. It means the first param of the callback is an error object, and the second param is the response data. You should handle the error properly.
Get account metadata
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
Get main account metadata by address
parameters:
- address {string}
Create account
parameters:
- params {object} the object detail can be find in this page
Update account
parameters:
- accountId {string}
- params {object} the object detail can be find in this page
Get account credits list
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
Get account content list
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
Get account groups list
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
Get account shares
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [application_status] {string} Status filter. "pending", "approved" or "declined".
Get account shares in a single group
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [application_status] {string} Status filter. "pending", "approved" or "declined".
Get account likes
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
Get account comments
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
Get account group applications
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [application_status] {string} Status filter. "pending", "approved" or "declined".
Get account share applications
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [application_status] {string} Status filter. "pending", "approved" or "declined".
Get account report list
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [application_status] {string} Status filter. "pending", "approved" or "declined".
Get account notifications
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [start_time] {number} List from this time. Unix timestamp.
Get account avatar metadata
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
Get account avatar raw image
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
Get address metadata
parameters:
- address {string}
parameters:
- params {object}
- accountId {string}
- [subAccountId] {string}
- [qs] {object}
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
Get account tokens data
parameters:
- params {object}
- accountId {string}
Get incentives list
parameters:
- params {object}
- accountId {string}
- [qs] {object}
- [start_date] {number} Query start date. Unix timestamp.
- [end_date] {number} Query end date. Unix timestamp.
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
Get incentives statistics list
parameters:
- params {object}
- accountId {string}
- [qs] {object}
- [start_date] {number} Query start date. Unix timestamp.
- [end_date] {number} Query end date. Unix timestamp.
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
Get incentives withdrawal list
parameters:
- params {object}
- accountId {string}
- [qs] {object}
- [start_date] {number} Query start date. Unix timestamp.
- [end_date] {number} Query end date. Unix timestamp.
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [status] {string} Status filter. "pending" or "done".
Withdraw incentives
parameters:
- accountId {string}
- params {object} the object detail can be find in this page
Get token pre-lock list
parameters:
- params {object}
- accountId {string}
- [qs] {object}
- [start_date] {number} Query start date. Unix timestamp.
- [end_date] {number} Query end date. Unix timestamp.
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [type] {string} Type filter. "lock" or "unlock".
Pre-lock tokens
parameters:
- accountId {string}
- params {object} the object detail can be find in this page
Unlock pre-locked tokens
parameters:
- accountId {string}
- params {object} the object detail can be find in this page
Get token lock list
parameters:
- params {object}
- accountId {string}
- [qs] {object}
- [start_date] {number} Query start date. Unix timestamp.
- [end_date] {number} Query end date. Unix timestamp.
- [page] {number} Page number. Starts from 0.
- [page_size] {number} Page size. Default to 20.
- [type] {string} Type filter. "content", "group_create", "group_join" or "report".
Get content metadata
parameters:
- params {object}
- contentId {string}
Get raw content
parameters:
- params {object}
- contentId {string}
Post content
parameters:
- params {object} the object detail can be find in this page
Update content
parameters:
- contentId {string}
- params {object} the object detail can be find in this page
Upgrade DTCP links before posting
- htmlContent {string}
Get share metadata
- params {object}
- shareId {string}
- qs {object}
- account_id {string}
Get the shares of a group share
- params {object}
- shareId {string}
- qs {object}
- page {number}
- page_size {number}
- account_id {string}
Get share reports
- params {object}
- shareId {string}
- qs {object}
- page {number}
- page_size {number}
- report_status {"pending"|"approved"|"declined"}
Report share
- shareId {string}
- params {object} the object detail can be find in this page
Get the likes of a group share
- params {object}
- shareId {string}
- qs {object}
- page {number}
- page_size {number}
- account_id {string}
Like a group share
- shareId {string}
- params {object} the object detail can be find in this page
Cancel the like of a group share
- shareId {string}
- likeId {string}
- params {object} the object detail can be find in this page
Get the comments of a group share
- params {object}
- shareId {string}
- qs {object}
- page {number}
- page_size {number}
- account_id {string}
Get replying comments of a comment
- params {object}
- commentId {string}
The way comment content is processed is the same as post content API.
- shareId {string}
- params {object} the object detail can be find in this page
Update the comment of a group share
- shareId {string}
- commentId {string}
- params {object} the object detail can be find in this page
Delete the comment of a group share
- shareId {string}
- commentId {string}
- params {object} the object detail can be find in this page
Get group metadata
- params {object}
- groupId {string}
- qs [object]
- account_id {string}
Create group
- params {object} the object detail can be find in this page
Update group
- groupId {string}
- params {object} the object detail can be find in this page
Update group
- groupId {string}
- params {object} the object detail can be find in this page
Get group members
- params {object}
- groupId {string}
- qs [object]
- page {number}
- page_size {number}
- application_status {"pending"|"approved"|"declined"}
Join group
- groupId {string}
- params {object} the object detail can be find in this page
Approve or decline member application
- groupId {string}
- groupMemberId {string}
- params {object} the object detail can be find in this page
Quit group or kick member out
- groupId {string}
- groupMemberId {string}
- params {object} the object detail can be find in this page
Get group member whitelist
- params {object}
- groupId {string}
- qs [object]
- page {number}
- page_size {number}
- application_status {"pending"|"approved"|"declined"}
Add group member whitelist
- groupId {string}
- params {object} the object detail can be find in this page
Approve or decline group member whitelist
- groupId {string}
- whitelistId {string}
- params {object} the object detail can be find in this page
Quit group member whitelist
- groupId {string}
- whitelistId {string}
- params {object} the object detail can be find in this page
Get group shares
- params {object}
- groupId {string}
- qs [object]
- page {number}
- page_size {number}
- application_status {"pending"|"approved"|"declined"}
Share to a group
- groupId {string}
- params {object} the object detail can be find in this page
Approve or decline share application
- shareId {string}
- params {object} the object detail can be find in this page
Delete group share
- shareId {string}
- params {object} the object detail can be find in this page
Get group avatar metadata
- params {object}
- groupId {string}
Get group avatar raw image
- params {object}
- groupId {string}
Get node list
- params [object]
- qs [object]
- page [number]
- page_size [number]
- qs [object]
Query all
- params [object]
- qs [object]
- page [number]
- page_size [number]
- text [string]
- type ["all"|"share"|"account"|"group"]
- category [string]
- qs [object]
Get system parameters
- params {object}
- accountId {string}
result_code | result_msg | description |
---|---|---|
0 | success | Success |
400 | client error | Client error |
401 | invalid data | Invalid post data |
402 | parse input JSON format error | Invalid JSON string |
403 | client signature error | Signature verification failed |
404 | input parameter error | Invalid parameter |
405 | input parameter empty | Empty parameter |
406 | nonce less than lasted | Nonce is used before |
500 | server error | Server error |