@ixo/client-sdk v1.11.1
ixo-client SDK
A complete package of client software for developing client applications which connect to the ixo software stack and build on the Internet of Impact.
Usage Example
const {makeWallet, makeClient} = require('@ixo/client-sdk')
const
wallet = await makeWallet(),
client = makeClient(wallet)
await client.register()
await client.sendTokens('<target address>', 10)
const someProject = await client.getProject('<a valid project DID>')
const someClaims = await client.listClaims(someProject)
console.log('Here are the claims', someClaims)
See wallet API and client API for details.
Wallet API
makeWallet(source, didPrefix = 'did:ixo:')
: Create a new wallet
source
: Either a mnemonic string or a plain object representing a wallet state (possibly obtained viatoJSON()
-see below for details). Optional.If empty, a brand new wallet is generated. If a mnemonic string, recovers a wallet based on the mnemonic. If a state object, revives the wallet using that state.
didPrefix
: A DID prefix. Optional, defaults todid:ixo:
.If the
source
is a mnemonic which means that you are importing a wallet from elsewhere, you may need to provide thedidPrefix
as well to obtain the exact same wallet. If the DID prefix of the wallet is different fromdid:ixo:
then it must be provided here.
makeWallet
returns a wallet object with the following
properties:
secp
: An instance of CosmJS' [Secp256k1HdWallet
](https://github.com/cosmos/cosmjs/tree/main/packages/launchpad#create-a-wallet)agent
: A custom wallet instance implementing [OfflineAminoSigner][offline-amino-signer]toJSON()
: Standard [toJSON
](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior) method forJSON.stringify
integration. One can also use this to get a representation of the wallet's internal state as a plain object and use it in a context where a class instance is not supported. (e.g. Global application state of a client app)
Client API
- [
makeClient
](#makeClient) to create a new client
Client methods:
- [
register
](#register) - [
getSecpAccount
](#getSecpAccount) - [
getAgentAccount
](#getAgentAccount) - [
balances
](#balances) - [
sendTokens
](#sendTokens) - [
getDidDoc
](#getDidDoc) - [
listProjects
](#listProjects) - [
listTemplates
](#listTemplates) - [
listCells
](#listCells) - [
getProject
](#getProject) - [
getTemplate
](#getTemplate) - [
getCell
](#getCell) - [
createProject
](#createProject) - [
updateProject
](#updateProject) - [
createEntityFile
](#createEntityFile) - [
getEntityFile
](#getEntityFile) - [
updateProjectStatus
](#updateProjectStatus) - [
getProjectFundAddress
](#getProjectFundAddress) - [
listAgents
](#listAgents) - [
createAgent
](#createAgent) - [
updateAgent
](#updateAgent) - [
listClaims
](#listClaims) - [
createClaim
](#createClaim) - [
evaluateClaim
](#evaluateClaim) - [
staking.listValidators
](#staking.listValidators) - [
staking.getValidator
](#staking.getValidator) - [
staking.myDelegations
](#staking.myDelegations) - [
staking.pool
](#staking.pool) - [
staking.validatorDistribution
](#staking.validatorDistribution) - [
staking.delegatorValidatorRewards
](#staking.delegatorValidatorRewards) - [
staking.delegation
](#staking.delegation) - [
staking.delegatorDelegations
](#staking.delegatorDelegations) - [
staking.delegatorUnbondingDelegations
](#staking.delegatorUnbondingDelegations) - [
staking.delegatorRewards
](#staking.delegatorRewards) - [
staking.delegate
](#staking.delegate) - [
staking.undelegate
](#staking.undelegate) - [
staking.redelegate
](#staking.redelegate) - [
bonds.byId
](#bonds.byId) - [
bonds.list
](#bonds.list) - [
bonds.buy
](#bonds.buy) - [
bonds.sell
](#bonds.sell) - [
custom
](#custom)
Create a new client
makeClient(signer, blockchainURL, blocksyncURL)
: Create a new ixo clientsigner
: Either a wallet object created by [makeWallet
](#makeWallet) or a custom signer object with the following properties:secp
: Object implementing [OfflineAminoSigner][offline-amino-signer]agent
: Object implementing [OfflineAminoSigner][offline-amino-signer] with the following extra property:did
See [the wallet API](#wallet-api) for more info on
secp
andagent
keywords.Optional. If empty, client methods that require a signer won't work.
blockchainURL
: The URL of the target ixo chain. Optional, defaults to the current mainnet URL.blocksyncURL
: The URL of the target ixo blocksync service. Optional, defaults to the current main blocksync service URL.
Client methods
register(pubKey)
: Register the current userpubKey
: Only required if the client is configured to use a custom signer. No need to provide this if the client is initialized with a wallet created with [makeWallet
](#makeWallet), as the value can be obtained from it.Note: Registering triggers a write operation on the blockchain which requires a gas fee in terms of ixo tokens to be paid. So the account you are trying to register has to have some ixo tokens. To credit accounts on the testnet you can use the [faucet](https://t.me/joinchat/I4_MXBmVGJKAMmEVX3SVaA). The specific address you will need to use is the address of the agent subwallet. Get it with
wallet.agent.getAccounts
. See [wallet API](#wallet-api) for more info.
getSecpAccount()
: Get account info for the SECP subwalletgetAgentAccount()
: Get account info for the agent subwalletsendTokens(targetAddress, amount, denom)
targetAddress
: A wallet address to send coins toamount
: Any positive numberdenom
: Coin type. Optional, defaults to"uixo"
.
getDidDoc(did)
: Return the full DID document for the given DIDlistProjects()
: Lists all available projectslistTemplates()
: Lists all available templateslistCells()
: Lists all available cellsgetProject(projectDid)
: Get complete project record for the given DIDgetTemplate(tplDid)
: Get complete template record for the given DIDgetCell(cellDid)
: Get complete cell record for the given DIDcreateProject(projectData, cellnodeURL)
: Create a new projectprojectData
: To be documented; for now please see [here](https://github.com/ixofoundation/ixo-apimodule/blob/master/src/common/dummyData.ts#L3-L207) for an examplecellnodeURL
: URL of the cell node where various project data will be kept. Optional, defaults to the URL of ixo's shared cell node
updateProject(projectDocUpdates, cellnodeURL)
: Update an existing projectprojectDocUpdates
: Updates to be made to the project document: A subset of theprojectData
argument of thecreateProject
method above that satisfies the rules described in the following link: https://github.com/ixofoundation/ixo-blockchain/pull/230#issue-902602327cellnodeURL
: URL of the cell node where various project data will be kept. Optional, defaults to the URL of ixo's shared cell node
createEntityFile(target, dataUrl)
: Upload a file to entity's cell nodetarget
: Either an entity record, an entity DID, or a cell node URLdataUrl
: Any valid [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs)
getEntityFile(target, key)
target
: Either an entity record, an entity DID, or a cell node URLkey
: Key of the target file, as returned fromcreateProjectFile
.
updateProjectStatus(target, status)
target
: Either a project record or a project DIDstatus
:"CREATED"
|"PENDING"
|"FUNDED"
|"STARTED"
|"STOPPED"
|"PAIDOUT"
Note I: Status is a state machine in that you can only update it in the order seen above. So
"CREATED"
->"PENDING"
is a valid transition while"CREATED"
->"STARTED"
is not.Note II: Before setting a project's status to
FUNDED
, you have to send some tokens to the project's wallet first. If you don't do that before trying to set the status toFUNDED
, you won't get an error but the status won't be changed either. This is because of a poor error handling logic in the ixo backend which is going to be fixed as soon as possible. For now just please keep this in mind. UsegetProjectFundAddress
below to get the wallet address to send tokens to.Use
getProjectFundAddress
below to get the wallet address to send tokens to.getProjectFundAddress(projectDid)
listAgents(projectRecordOrDid)
: List agents belonging to a given projectcreateAgent(projectRecordOrDid, agentRecord)
: Create an agent for the given projectagentRecord
: An object with the following properties:did
: The DID of an already registered useremail
: Agent emailname
: Agent namerole
: Any one of the following:"PO"
for owner"EA"
for evaluator"SA"
for service provider"IA"
for investor
Note: The new agent will need to be approved before they can start their activity. See
updateAgent
below:
updateAgent(projectRecordOrDid, agentDid, updates)
updates
: An object with the following properties:status
(Required): Any one of the following:0
for pending1
for approved2
for revoked3
for invited
role
(Required): See therole
property undercreateAgent
version
: Optional
listClaims(projectRecordOrDid, projectTemplateId)
projectTemplateId
: Optional, provide a value to filter claims by template id
createClaim(projectRecordOrDid, templateRecordOrDid, claimItems, opts)
claimItems
: Array of objects that has the following schema:id
: Id of the claim item. Must match the value in the claim template.attribute
: Attribute of the claim item. Must match the value in the claim template.value
: Value of the claim item.
opts
: An object with the following properties:dryRun
: Boolean, defaultfalse
. Iftrue
, Instead of creating the claims, returns the full HTTP request that will create the claims.
evaluateClaim(projectRecordOrDid, claimId, status)
claimId
: A claim id as returned fromcreateClaim
status
: Any one of the following:0
for pending1
for approved2
for rejected
staking
:An object that groups the following staking related methods:
listValidators(urlParams)
See [here](https://testnet.ixo.world/swagger/#/Staking/get_staking_validators) for a description of the url params of the related endpoint, and its return value.
getValidator(validatorAddress)
See [here](https://testnet.ixo.world/swagger/#/Staking/getstaking_validators__validatorAddr]) for the return value.
myDelegations()
See [here](https://testnet.ixo.world/swagger/#/Staking/get_staking_delegatorsdelegatorAddrdelegations) for the return value.
pool()
See [here](https://testnet.ixo.world/swagger/#/Staking/get_staking_pool) for the return value.
validatorDistribution(validatorAddress)
See [here](https://testnet.ixo.world/swagger/#/Distribution/getdistribution_validators__validatorAddr) for the return value.
delegatorValidatorRewards(delegatorAddress, validatorAddress)
See [here](https://testnet.ixo.world/swagger/#/Distribution/getdistribution_delegatorsdelegatorAddrrewards__validatorAddr) for the return value.
delegation(delegatorAddr, validatorAddress)
See [here](https://testnet.ixo.world/swagger/#/Staking/getstaking_delegatorsdelegatorAddrdelegations__validatorAddr) for the return value.
delegatorDelegations(delegatorAddress)
See [here](https://testnet.ixo.world/swagger/#/Staking/get_staking_delegatorsdelegatorAddrdelegations) for the return value.
delegatorUnbondingDelegations(delegatorAddress)
See [here](https://testnet.ixo.world/swagger/#/Staking/get_staking_delegatorsdelegatorAddrunbonding_delegations) for the return value.
delegatorRewards(delegatorAddress)
See [here](https://testnet.ixo.world/swagger/#/Distribution/get_distribution_delegatorsdelegatorAddrrewards) for the return value.
balances(accountType, denom)
accountType
: Eithersecp
oragent
.denom
: Optional coin name. If provided, only the balance for the given coin will be returned.See [here](https://testnet.ixo.world/swagger/#/Query/AllBalances) or [here](https://testnet.ixo.world/swagger/#/Query/Balance) for the return value.
delegate(validatorAddress, amount)
undelegate(validatorAddress, amount)
redelegate(validatorSourceAddress, validatorDestinationAddress)
bonds
:An object that groups the following bond related methods:
byId(did)
list()
buy({bondDid, bondToken, reserveToken, amount, maxPrice})
sell({bondDid, bondToken, amount})
custom(walletType, msg)
: Send a custom message to the blockchainwalletType
: Either"secp"
or"agent"
. See [the wallet API](#wallet-api) for more infomsg
: See [here](https://github.com/ixofoundation/ixo-client-sdk/blob/74725d861ac7cf73e8983ce3dc9d91868cd4ce62/messages.md) for available options
Debugging
Put the ixo-client-sdk
string into your DEBUG
environment
variable to log network requests and responses. See [the debug
package](https://www.npmjs.com/package/debug) for more info.
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