decentr-js v5.3.6
decentr-js
decentr-js
✨ Features
- Mnemonic generation (24 words combination)
- Wallet generation based on mnemonic (address, private key, public key)
- Querying to almost all decentr services
- Creating and broadcasting transactions
🔧 Installation
npm install decentr-js
🎬 Getting started
#Table of contents
1. Mnemonic
2. Wallet
3. Decentr API
1. Status
2. Auth
3. Bank
4. Blocks
5. Community
6. Distribution
7. Mint
8. Operations
9. Staking
10. Token
11. Tx
4. Cerberus API
1. Configuration
2. Image
3. PDV
4. Profile
5. Rewards
5. Theseus API
1. DDV
2. Posts
3. Profile
6. Vulcan API
1. Referral
2. Registration
3. Loan
7. License
Mnemonic
Generate mnemonic phrase (24 words)
import { generateMnemonic } from 'decentr-js';
const mnemonic = generateMnemonic();
/*
fantasy scatter misery seminar resist file unique coral ordinary wash shoulder demise bubble calm sail protect divide write lend card sudden rally depart park
*/
Wallet
Create wallet with address and keys
import { createWalletFromMnemonic } from "decentr-js"
const seed = ...12 seed words here
const wallet = createWalletFromMnemonic(seed);
/*
{
address: 'decentr1j6e6j53vh95jcq9k9lnsrsvj3h8dkdgmm20zhu',
validatorAddress: 'decentrvaloper1p4s4djk5dqstfswg6k8sljhkzku4a6ve9dmng5',
privateKey: '8c313682470073d56d2d8f5b7fde53c072024a9fd9135501125035d53c8a1f60',
publicKey: '03dae8cf229d1db63c8d854bd1c73e280147ebd3bb40df12381d16b0eb071a72b6'
}
*/
Using Decentr api
Decentr client
For less text, we define some basic variables here
import { DecentrClient } from 'decentr-js';
const NODE_URL = 'http://rest.testnet.decentr.xyz:26657'; // blockchain node
const privateKey = 'decentrPrivateKey'; // optional, if you do not need to use sign functionality
const decentrClient = await DecentrClient.create(NODE_URL, privateKey);
Status
const status = await decentrClient.status();
Response of status
method is a [StatusResponse](https://github.com/cosmos/cosmjs/blob/e7b107a0d0419fbd5280645a70153548235617fa/packages/tendermint-rpc/src/tendermint34/responses.ts#L127).
📜 Auth
Auth client has the following interface
class AuthClient {
getAccount(walletAddress: Wallet['address']): Promise<Account | null>;
}
How to get instance of auth client
const authClient = decentrClient.auth;
Methods
- Get account
const walletAddress = 'decentr1234567890abcdefghijklmno';
const account = await authClient.getAccount(walletAddress);
Response of getAccount
method is an [Account](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/stargate/src/accounts.ts#L15) or null
if account is not exist.
📜 Bank
Bank client has the following interface
class BankClient {
getBalance(walletAddress: Wallet['address']): Promise<Coin[]>;
getDenomBalance(walletAddress: Wallet['address'], denom: string): Promise<Coin>;
getSupply(): Promise<Coin[]>;
getDenomSupply(denom: string): Promise<Coin>;
public sendTokens(
request: SendTokensRequest,
): TransactionSigner;
}
How to get instance of bank client
const bankClient = decentrClient.bank;
Methods
- Get balance
const walletAddress = 'decentr1234567890abcdefghijklmno';
const balance = await bankClient.getBalance(decentr1234567890abcdefghijklmno);
Response of getBalance
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3) array.
- Get denom balance
const walletAddress = 'decentr1234567890abcdefghijklmno';
const denom = 'udec';
const denomBalance = await bankClient.getDenomBalance(decentr1234567890abcdefghijklmno, denom);
Notice: denom
is an optional param, it is udec
by default.
Response of getDenomBalance
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3).
- Get supply
const walletAddress = 'decentr1234567890abcdefghijklmno';
const supply = await bankClient.getSupply(decentr1234567890abcdefghijklmno);
Response of getSupply
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3) array.
- Get denom supply
const denom = 'udec';
const denomSupply = await bankClient.getDenomSupply(denom);
Notice: denom
is an optional param, it is udec
by default.
Response of getDenomSupply
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3).
- Send tokens
const message = {
fromAddress: 'decentrFromAddress',
toAddress: 'decentrToAddress',
amount: [
{
amount: '100000000',
denom: 'udec',
},
],
};
const transactionSigner = bankClient.sendTokens(message);
transactionSigner
is an interface that allows simulate
or broadcast
transaction
const gas = await transactionSigner.simulate(); // estimated gas that will be spent on broadcasting
const transaction = await transactionSigner.signAndBroadcast('My gift to decentr user');
Response of signAndBroadcast
method is a DeliverTxResponse.
📜 Blocks
Blocks client has the following interface
class BlocksClient {
getBlock(height?: BlockHeader['height']): Promise<Block>;
}
How to get instance of bank client
const blocksClient = decentrClient.blocks;
Methods
- Get block
const height = 12345;
const block = await blocksClient.getBlock(decentr1234567890abcdefghijklmno)
Notice: height
is an optional param, method will return the latest block if height
is not supplied.
Response of getBlock
method is a [Block](https://github.com/Decentr-net/decentr.js/blob/master/src/api/blockchain/cosmos/blocks/types.ts#L7).
📜 Community
Community client has the following interface
class CommunityClient {
getModeratorAddresses(): Promise<Wallet['address'][]>;
getFollowees(follower: Wallet['address']): Promise<Wallet['address'][]>;
createPost(
request: MsgCreatePost['post'],
): TransactionSigner;
deletePost(
request: MsgDeletePost,
): TransactionSigner;
setLike(
request: MsgSetLike['like'],
): TransactionSigner;
follow(
request: MsgFollow,
): TransactionSigner;
unfollow(
request: MsgUnfollow,
): TransactionSigner;
}
How to get instance of community client
const communityClient = decentrClient.community;
Methods
- Get moderators
const moderators = await communityClient.getModeratorAddresses();
Response of getModeratorAddresses
method is a wallet addresses array;
- Get followees
const walletAddress = 'decentr123456789abcdefghijklmno';
const followees = await communityClient.getFollowees(walletAddress);
Response of getFollowees
method is a wallet address array;
- Create post
import { PostCategory } from 'decentr-js';
const message = {
owner: 'decentrAuthorAddress', // author's walletAddress
uuid: '12345-abcde-67890-fghijk',
title: 'Post title',
previewImage: 'http://image.png',
category: PostCategory.CATEGORY_TRAVEL_AND_TOURISM,
text: 'Post text',
};
const transactionSigner = communityClient.createPost(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
- Delete post
const message = {
postOwner: 'decentrAuthorAddress',
postUuid: '12345-abcde-67890-fghijk',
owner: 'decentrInitiatorAddress',
};
const transactionSigner = communityClient.deletePost(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
- Set like
import { LikeWeight } from 'decentr-js'
const message = {
postOwner: 'decentrAuthorAddress',
postUuid: '12345-abcde-67890-fghijk',
owner: 'decentrInitiatorAddress',
weight: LikeWeight.LIKE_WEIGHT_UP,
};
const transactionSigner = communityClient.deletePost(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
- Follow
import { LikeWeight } from 'decentr-js'
const message = {
owner: 'decentrFollowerAddress',
whom: 'decentrWhomToFollowAddress',
};
const transactionSigner = communityClient.deletePost(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
- Unfollow
import { LikeWeight } from 'decentr-js'
const message = {
owner: 'decentrFollowerAddress',
whom: 'decentrWhomToUnfollowAddress',
};
const transactionSigner = communityClient.deletePost(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
📜 Distribution
Distribution client has the following interface
class DistributionClient {
getCommunityPool(): Promise<Coin[]>;
getDistributionParameters(): Promise<Params>;
getDelegatorRewards(delegatorAddress: Wallet['address']): Promise<QueryDelegationTotalRewardsResponse>;
getDelegatorRewardsFromValidator(
delegatorAddress: Wallet['address'],
validatorAddress: Validator['operatorAddress'],
): Promise<Coin[]>;
getWithdrawAddress(delegatorAddress: Wallet['address']): Promise<Wallet['address']>;
getValidatorCommission(validatorAddress: Validator['operatorAddress']): Promise<Coin[]>;
getValidatorOutstandingRewards(validatorAddress: Validator['operatorAddress']): Promise<Coin[]>;
setWithdrawAddress(
request: SetWithdrawAddressRequest,
): TransactionSigner;
withdrawDelegatorRewards(
request: WithdrawDelegatorRewardRequest,
): TransactionSigner;
withdrawValidatorRewards(
request: WithdrawValidatorCommissionRequest,
): TransactionSigner;
}
How to get instance of distribution client
const distributionClient = decentrClient.distribution;
Methods
- Get community pool
const communityPool = await distributionClient.getCommunityPool();
Response of getCommunityPool
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3) array.
- Get parameters
const parameters = await distributionClient.getDistributionParameters(walletAddress);
Response of getDistributionParameters
method is a [Params](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/distribution/v1beta1/distribution.ts#L9);
- Get delegator rewards
const delegatorAddress = 'decentrDelegatorAddress';
const delegatorRewards = await distributionClient.getDelegatorRewards(delegatorAddress);
Response of getDelegatorRewards
method is a [QueryDelegationTotalRewardsResponse](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/distribution/v1beta1/query.ts#L119)
- Get delegator rewards from validator
const delegatorAddress = 'decentrDelegatorAddress';
const validatorAddress = 'decentrvaloperValidatorAddress';
const delegatorRewards = await distributionClient.getDelegatorRewardsFromValidator(delegatorAddress, validatorAddress);
Response of getDelegatorRewardsFromValidator
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3) array.
- Get withdraw address
const walletAddress = 'decentrWalletAddress';
const withdrawAddress = await distributionClient.getWithdrawAddress(walletAddress);
Response of getWithdrawAddress
method is a wallet address where staking rewards will be transferred;
- Get validator commission
const validatorAddress = 'decentrvaloperValidatorAddress';
const commission = await distributionClient.getValidatorCommission(validatorAddress);
Response of getValidatorCommission
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3) array.
- Get validator outstanding rewards
const validatorAddress = 'decentrvaloperValidatorAddress';
const outstandingRewards = await distributionClient.getValidatorOutstandingRewards(validatorAddress);
Response of getValidatorOutstandingRewards
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3) array.
- Set withdraw address
const message = {
delegatorAddress: 'decentrDelegatorAddress',
withdrawAddress: 'decentrWithdrawAddrews',
};
const transactionSigner = distributionClient.setWithdrawAddress(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
- Withdraw delegator rewards
const messages = [
{
delegatorAddress: 'decentrDelegatorAddress',
validatorAddress: 'decentrWithdrawAddrews1',
},
{
delegatorAddress: 'decentrDelegatorAddress',
validatorAddress: 'decentrWithdrawAddrews2',
},
];
const transactionSigner = distributionClient.withdrawDelegatorRewards(messages);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
- Withdraw validator rewards
const message = {
validatorAddress: 'decentrvaloperValidatorAddress',
};
const transactionSigner = distributionClient.withdrawValidatorRewards(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
📜 Mint
Mint client has the following interface
class MintClient {
getInflation(): Promise<string>;
}
How to get instance of mint client
const mintClient = decentrClient.mint;
Methods
- Get inflation
const inflation = await mintClient.getInflation();
Response of getInflation
method is a string like 0.135
.
📜 Operations
Operations client has the following interface
class OperationsClient {
getMinGasPrice(): Promise<Coin>;
resetAccount(
request: ResetAccountRequest,
): TransactionSigner;
}
How to get instance of operations client
const operationsClient = decentrClient.operations;
Methods
- Get min gas price
const minGasPrice = await operationsClient.getMinGasPrice();
Response of getMinGasPrice
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3)
- Reset account
const message = {
owner: 'decentrInitiatorAddress',
address: 'decentrResetAddress',
};
const transactionSigner = operationsClient.resetAccount(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
📜 Staking
Staking client has the following interface
class StakingClient {
getPool(): Promise<Pool>;
getValidators(status: BondStatusString): Promise<Validator[]>;
getValidator(address: Validator['operatorAddress']): Promise<Validator>;
getDelegations(delegatorAddress: Wallet['address']): Promise<DelegationResponse[]>;
getDelegation(
delegatorAddress: Wallet['address'],
validatorAddress: Validator['operatorAddress'],
): Promise<Coin | null>;
getValidatorDelegations(validatorAddress: Validator['operatorAddress']): Promise<DelegationResponse[]>;
getUnbondingDelegations(delegatorAddress: Wallet['address']): Promise<UnbondingDelegation[]>;
getUnbondingDelegation(
delegatorAddress: Wallet['address'],
validatorAddress: Validator['operatorAddress'],
): Promise<UnbondingDelegation | undefined>;
getValidatorUnbondingDelegations(
validatorAddress: Validator['operatorAddress'],
): Promise<UnbondingDelegation[]>;
getRedelegations(
delegatorAddress: Wallet['address'],
sourceValidatorAddress: Validator['operatorAddress'],
destinationValidatorAddress: Validator['operatorAddress'],
): Promise<RedelegationResponse[]>;
getDelegatorValidators(
delegatorAddress: Wallet['address'],
): Promise<Validator[]>;
getStakingParameters(): Promise<Params>;
delegateTokens(
request: DelegateTokensRequest,
): TransactionSigner;
undelegateTokens(
request: UndelegateTokensRequest,
): TransactionSigner;
redelegateTokens(
request: RedelegateTokensRequest,
): TransactionSigner;
}
How to get instance of staking client
const stakingClient = decentrClient.staking;
Methods
- Get pool
const pool = await stakingClient.getPool();
Response of pool
method is a [Pool](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L292)
- Get validators
const validators = await stakingClient.getValidators('BOND_STATUS_BONDED');
Response of getValidators
method is a [Validator](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L117) array.
- Get validator
const validatorAddress = 'decentrvaloperValidatorAddress';
const validator = await stakingClient.getValidator(validatorAddress);
Response of getDelegatorRewards
method is a [Validator](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L117)
- Get delegations
const delegatorAddress = 'decentrDelegatorAddress';
const delegations = await stakingClient.getDelegations(delegatorAddress);
Response of getDelegatorRewardsFromValidator
method is a [DelegationResponse](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L263) array.
- Get delegation
const delegatorAddress = 'decentrDelegatorAddress';
const validatorAddress = 'decentrvaloperValidatorAddress';
const delegation = await stakingClient.getDelegation(delegatorAddress, validatorAddress);
Response of getDelegation
method is a [Coin](https://github.com/cosmos/cosmjs/blob/57a56cfa6ae8c06f4c28949a1028dc764816bbe8/packages/amino/src/coins.ts#L3) array.
- Get validator delegations
const validatorAddress = 'decentrvaloperValidatorAddress';
const validatorDelegations = await stakingClient.getValidatorDelegations(validatorAddress);
Response of getValidatorDelegations
method is a [DelegationResponse](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L263) array.
- Get unbonding delegations
const delegatorAddress = 'decentrDelegatorAddress';
const unbondingDelegations = await stakingClient.getUnbondingDelegations(delegatorAddress);
Response of getUnbondingDelegations
method is a [UnbondingDelegation](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L197) array.
- Get unbonding delegation
const delegatorAddress = 'decentrDelegatorAddress';
const validatorAddress = 'decentrvaloperValidatorAddress';
const unbondingDelegation = await stakingClient
.getUnbondingDelegation(delegatorAddress, validatorAddress);
Response of getUnbondingDelegation
method is a [UnbondingDelegation](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L197)
- Get validator unbonding delegations
const validatorAddress = 'decentrvaloperValidatorAddress';
const unboindingDelegations = await stakingClient
.getValidatorUnbondingDelegations(validatorAddress, validatorAddress);
Response of getValidatorUnbondingDelegations
method is a [UnbondingDelegation](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L197) array.
- Get redelegations
const delegatorAddress = 'decentrDelegatorAddress';
const sourceValidatorAddress = 'decentrvaloperSourceValidatorAddress';
const destinationValidatorAddress = 'decentrvaloperDestinationValidatorAddress';
const redelegations = await stakingClient.getRedelegations(
delegatorAddress,
sourceValidatorAddress,
destinationValidatorAddress,
);
Response of getRedelegations
method is a [RedelegationResponse](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L283) array.
- Get delegator validators
const delegatorAddress = 'decentrDelegatorAddress';
const validators = await stakingClient.getDelegatorValidators(delegatorAddress);
Response of getDelegatorValidators
method is a [Validator](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L117) array.
- Get staking parameters
const parameters = await stakingClient.getStakingParameters();
Response of getStakingParameters
method is a [Params](https://github.com/confio/cosmjs-types/blob/e3e0c4ba52d38af45522f5705c24eb734494b9a4/src/cosmos/staking/v1beta1/staking.ts#L246)
- Delegate tokens
const message = {
delegatorAddress: 'decentrDelegatorAddress',
validatorAddress: 'decentrvaloperValidatorAddress',
amount: [
{
amount: '100000000',
denom: 'udec',
},
],
};
const transactionSigner = stakingClient.delegateTokens(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
- Undelegate tokens
const message = {
delegatorAddress: 'decentrDelegatorAddress',
validatorAddress: 'decentrvaloperValidatorAddress',
amount: {
amount: '100000000',
denom: 'udec',
},
};
const transactionSigner = stakingClient.undelegateTokens(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
- Redelegate tokens
const message = {
delegatorAddress: 'decentrDelegatorAddress',
validatorSrcAddress: 'decentrvaloperSourceValidatorAddress',
validatorDstAddress: 'decentrvaloperDestinationValidatorAddress',
amount: {
amount: '100000000',
denom: 'udec',
},
};
const transactionSigner = stakingClient.redelegateTokens(message);
Notice: more about transactionSigner
you can read [here](#transactionSigner)
📜 Token
Token client has the following interface
class TokenClient {
getBalance(walletAddress: Wallet['address']): Promise<string>;
}
How to get instance of token client
const tokenClient = decentrClient.token;
Methods
- Get PDV balance
const walletAddress = 'decentrWalletAddress';
const balance = await tokenClient.getBalance(walletAddress);
Response of getBalance
method is a string like 1.001234
.
📜 Tx
Tx client has the following interface
class TxClient {
search(query: SearchTxQuery,filter: SearchTxFilter = {}): Promise<DecodedIndexedTx[]>
getByHash(hash: IndexedTx['hash']): Promise<DecodedIndexedTx>;
}
How to get instance of tx client
const txClient = decentrClient.tx;
Methods
- Search txs
const queryByHeight = { height: 123456 };
const txsByHeight = await txClient.search(queryByHeight);
const queryBySentFromOrTo = { sentFromOrTo: 'decentrWalletAddress' };
const txsBySentFromOrTo = await txClient.search(queryByHeight);
const queryByTags = { tags: [
{
key: 'message.module',
value: 'staking',
},
{
key: 'message.sender',
value: 'decentrWalletAddress',
},
],
};
const txsByTags = await txClient.search(queryByHeight);
Response of search
method is an [DecodedIndexedTx](https://github.com/Decentr-net/decentr.js/blob/master/src/api/blockchain/cosmos/tx/types.ts#L11) array.
- Get by hash
const txHash = 'ABCDEF0123456GHIJKL7890';
const tx = await txClient.getByHash(txHash);
Response of getByHash
method is an [DecodedIndexedTx](https://github.com/Decentr-net/decentr.js/blob/master/src/api/blockchain/cosmos/tx/types.ts#L11)
Using Cerberus api
Cerberus client
For less text, we define some basic variables here
import { CerberusClient } from 'decentr-js';
const CERBERUS_URL = 'https://cerberus.mainnet.decentr.xyz';
const cerberusClient = new CerberusClient(CERBERUS_URL);
📜 Configuration
Configuration client has the following interface
class CerberusConfigurationClient {
getPDVBlacklist(): Promise<PDVBlacklist>;
getPDVRewards(): Promise<PDVRewards>;
}
How to get instance of configuration client
const configurationClient = cerberusClient.configuration;
Methods
- Get PDV blacklist
const pDVBlacklist = await configurationClient.getPDVBlacklist();
Response of getPDVBlacklist
method is a [PDVBlacklist](https://github.com/Decentr-net/decentr.js/blob/master/src/api/cerberus/configuration/types.ts#L3)
- Get PDV rewards configuration
const pDVRewards = await configurationClient.getPDVRewards();
Response of getPDVRewards
method is a [PDVRewards](https://github.com/Decentr-net/decentr.js/blob/master/src/api/cerberus/configuration/types.ts#L7)
📜 Image
Image client has the following interface
class CerberusImageClient {
save(image: File, privateKey: Wallet['privateKey']): Promise<SaveImageResponse>;
}
How to get instance of image client
const imageClient = cerberusClient.image;
Methods
- Save image
const image = 'your image file of File interface';
const privateKey = '1234567890abcdefghijklmno';
const imageResponse = await imageClient.saveImage(image, privateKey);
Response of saveImage
method is an [SaveImageResponse](https://github.com/Decentr-net/decentr.js/blob/master/src/api/cerberus/image/types.ts#L1)
📜 PDV
PDV client has the following interface
class CerberusPDVClient {
getPDVList(
walletAddress: Wallet['address'],
paginationOptions?: PDVListPaginationOptions,
): Promise<PDVListItem[]>;
getPDVMeta(pdvAddress: number, walletAddress: Wallet['address']): Promise<PDVMeta>;
getPDVDetails(pdvAddress: number, wallet: Wallet): Promise<PDVDetails>;
sendPDV(pdv: PDV[], privateKey: Wallet['privateKey']): Promise<PDVAddress>;
validate(pdv: PDV[]): Promise<number[]>;
}
How to get instance of PDV client
const pDVClient = cerberusClient.pdv;
Methods
- Get PDV list
const walletAddress = 'decentrPDVOwnerAddress';
const pagination = {
limit: 20,
from: 12345678, // optional, timestamp of previous PDVListItem
};
const pdvList = operationsClient.getPDVList(walletAddress, pagination);
Response of getPDVList
method is an id (timestamp) array like [1641748368, 1641744563, 164158725]
- Get PDV meta
const walletAddress = 'decentrPDVOwnerAddress';
const pDVAddress = 1641748368;
const pDVMeta = await pDVClient.getPDVMeta(pDVAddress, walletAddress);
Response of getPDVMeta
method is a [PDVMeta](https://github.com/Decentr-net/decentr.js/blob/master/src/api/cerberus/pdv/types.ts#L91)
- Get PDV details
const wallet = {
address: 'decentrPDVOwnerAddress',
privateKey: '1234567890abcdefghijklmno',
publicKey: 'abcdefghijklmno1234567890',
};
const pDVAddress = 1641748368;
const pDVDetails = await pDVClient.getPDVDetails(pDVAddress, wallet);
Response of getPDVDetails
method is a [PDVDetails](https://github.com/Decentr-net/decentr.js/blob/master/src/api/cerberus/pdv/types.ts#L86)
- Send PDV
const PDV = []; // array of your PDV's;
const privateKey: '1234567890abcdefghijklmno';
const pDVAddress = await pDVClient.sendPDV(pdv, privateKey);
Response of sendPDV
method is an id (timestamp) of PDV.
- Validate PDV
const PDV = []; // array of your PDV's;
const invalidPDVIndexes = await pDVClient.validate(pdv);
Response of validate
method is an indexes array of invalid PDV.
📜 Profile
Profile client has the following interface
class CerberusProfileClient {
setProfile(
profile: ProfileUpdate,
privateKey: Wallet['privateKey'],
): Promise<PDVAddress>;
getProfile(
walletAddress: Wallet['address'],
privateKey: Wallet['privateKey'],
): Promise<Profile>;
getProfiles(
walletAddresses: Wallet['address'][],
privateKey: Wallet['privateKey'],
): Promise<Record<Profile['address'], Profile>>;
}
How to get instance of PDV client
const profileClient = cerberusClient.profile;
Methods
- Set profile
import { Gender } from 'decentr-js';
const profile = {
avatar: 'http://avatar.png',
bio: 'bio',
birthday: '1991-01-01',
emails: ['email@email.com'],
firstName: 'firstName', // maxlength: 64
gender: Gender.Male,
lastName: 'lastName', // maxlength: 64
}
const privateKey = '1234567890abcdefghijklmno';
const pDVAddress = await profileClient.setProfile(profile, privateKey);
Response of setProfile
method is an id (timestamp) of PDV.
- Get profile
const walletAddress = 'decentrAddress';
const privateKey = '1234567890abcdefghijklmno';
// privateKey is an optional param required to get private profile data (birthday, gender etc.)
const profile = await profileClient.getProfile(walletAddress, privateKey);
Response of getProfile
method is a [Profile](https://github.com/Decentr-net/decentr.js/blob/master/src/api/cerberus/profile/types.ts#L4)
- Get profiles
const walletAddresses = ['decentrAddress1', 'decentrAddress2'];
const privateKey = '1234567890abcdefghijklmno';
// privateKey is an optional param required to get private profile data only for request initiator profile (birthday, gender etc.)
const profiles = await profileClient.getProfiles(walletAddress, privateKey);
Response of getProfiles
method is an object of type { decentrAddress1: profileObj1, decentrAddress2: profileObj2 }
.
📜 Rewards
Rewards client has the following interface
class CerberusRewardsClient {
getDelta(walletAddress: Wallet['address']): Promise<TokenDelta>;
getPool(): Promise<TokenPool>;
}
How to get instance of rewards client
const rewardsClient = cerberusClient.rewards;
Methods
- Get delta
const walletAddress = 'decentrWalletAddress';
const delta = await tokenClient.getDelta(walletAddress);
Response of getDelta
method is an [TokenDelta](https://github.com/Decentr-net/decentr.js/blob/master/src/api/cerberus/rewards/types.ts#L7)
- Get pool
const pool = await tokenClient.getPool();
Response of getPool
method is an [TokenPool](https://github.com/Decentr-net/decentr.js/blob/master/src/api/cerberus/rewards/types.ts#L1)
Using Theseus api
Theseus client
For less text, we define some basic variables here
import { TheseusClient } from 'decentr-js';
const THESEUS_URL = 'https://theseus.mainnet.decentr.xyz';
const theseusClient = new TheseusClient(THESEUS_URL);
📜 DDV
DDV client has the following interface
class TheseusDDVClient {
getStats(): Promise<DDVStats>;
}
How to get instance of ddv client
const ddvClient = theseusClient.ddv;
Methods
- Get stats
const stats = await ddvClient.getStats();
Response of getStats
method is a [DDVStats](https://github.com/Decentr-net/decentr.js/blob/master/src/api/theseus/ddv/types.ts#L6)
📜 Posts
Posts client has the following interface
class TheseusPostsClient {
getPost(params: Pick<Post, 'owner' | 'uuid'>, requestedBy: Wallet['address']): Promise<PostResponse>;
getPosts(filterOptions?: PostsListFilterOptions): Promise<PostsListResponse>;
}
How to get instance of profile client
const postsClient = theseusClient.posts;
Methods
- Get post
const postParams = {
owner: 'decentrWalletAddress',
uuid: 'post-uuid-1234',
};
const requestedBy = 'decentrSameOrAnotherWalletAddress';
const stats = await postsClient.getPost(postParams, requestedBy);
Response of getPost
method is a [PostResponse](https://github.com/Decentr-net/decentr.js/blob/master/src/api/theseus/posts/types.ts#L31)
- Get posts
const filter = {
category: PostCategory.CATEGORY_WORLD_NEWS,
requestedBy: 'decentrSameOrAnotherWalletAddress',
}; // optional
const balance = await postsClient.getPosts(filter);
Interface of filter
object described here [PostsListFilterOptions](https://github.com/Decentr-net/decentr.js/blob/master/src/api/theseus/posts/types.ts#L15)
Response of getPosts
method is an [PostsListResponse](https://github.com/Decentr-net/decentr.js/blob/master/src/api/theseus/posts/types.ts#L40)
📜 Profile
Profile client has the following interface
class TheseusProfileClient {
getProfileStats(walletAddress: Wallet['address']): Promise<ProfileStatistics>;
getAdvDdvStats(): Promise<AdvDdvStatistics>;
}
How to get instance of profile client
const profileClient = theseusClient.profile;
Methods
- Get profile stats
const walletAddress = 'decentrAddress';
const stats = await profileClient.getProfileStats(walletAddress);
Response of getProfileStats
method is a [ProfileStatistics](https://github.com/Decentr-net/decentr.js/blob/master/src/api/theseus/profile/types.ts#L11)
- Get ADV/DDV stats
const walletAddress = 'decentrWalletAddress';
const balance = await profileClient.getAdvDdvStats();
Response of getAdvDdvStats
method is an [AdvDdvStatistics](https://github.com/Decentr-net/decentr.js/blob/master/src/api/theseus/profile/types.ts#L1)
Using Vulcan api
Vulcan client
For less text, we define some basic variables here
import { VulcanClient } from 'decentr-js';
const VULCAN_URL = 'https://vulcan.mainnet.decentr.xyz';
const vulcanClient = new VulcanClient(VULCAN_URL);
📜 Referral
Referral client has the following interface
class VulcanReferralClient {
getCode(walletAddress: Wallet['address']): Promise<string>;
getConfig(): Promise<ReferralConfig>;
getStats(walletAddress: Wallet['address']): Promise<ReferralTimeStats>;
trackInstall(walletAddress: Wallet['address']): Promise<void>;
}
How to get instance of referral client
const referralClient = vulcanClient.referral;
Methods
- Get code
const walletAddress = 'decentrAddress';
const code = await referralClient.getCode(walletAddress);
Response of getCode
method is a string code like abc123
- Get configuration
const config = await referralClient.getConfig();
Response of getConfig
method is an [ReferralConfig](https://github.com/Decentr-net/decentr.js/blob/master/src/api/vulcan/referral/types.ts#L14)
- Get statistics
const walletAddress = 'decentrAddress';
const stats = await referralClient.getStats();
Response of getStats
method is an [ReferralTimeStats](https://github.com/Decentr-net/decentr.js/blob/master/src/api/vulcan/referral/types.ts#L28)
- Track install
const walletAddress = 'decentrAddress';
await referralClient.trackInstall(walletAddress);
📜 Registration
Registration client has the following interface
class VulcanReferralClient {
register(walletAddress: Wallet['address'], email: string): Promise<void>;
confirm(email: string, code: string): Promise<void>;
hesoyam(walletAddress: Wallet['address']): Promise<void>;
getStats(): Promise<RegistrationStats>;
}
How to get instance of registration client
const registrationClient = vulcanClient.registration;
Methods
- Register user
const walletAddress = 'decentrAddress';
const email = 'email@email.com';
await registrationClient.register(walletAddress, email);
- Confirm registration
const email = 'email@email.com';
const code = 'a1b2c3';
await registrationClient.confirm(email, code);
- Hesoyam
const walletAddress = 'decentrAddress';
await registrationClient.hesoyam(walletAddress);
- Get stats
await registrationClient.getStats();
Response of getStats
method is an [RegistrationStats](https://github.com/Decentr-net/decentr.js/blob/master/src/api/vulcan/registration/types.ts#L6)
📜 Loan
Loan client has the following interface
class VulcanLoanClient {
requestLoan(loan: Loan): Promise<void>;
}
How to get instance of loan client
const loanClient = vulcanClient.loan;
Methods
- Request loan
const loan = {
firstName: "John",
lastName: "Doe", *(Optional)*
pdvRate: 1.12345678,
walletAddress: "decentrAddress"
}
await loanClient.requestLoan(loan);
🥂 License
[MIT](./LICENSE.md) as always
11 days ago
17 days ago
17 days ago
2 months ago
2 months ago
7 months ago
8 months ago
9 months ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago