community-js / community / default
community.default
- create
- finalize
- get
- getActionCost
- getBalance
- getCommunityContract
- getContractSourceId
- getCreateCost
- getFee
- getMainContractId
- getRole
- getState
- getUnlockedBalance
- getVaultBalance
- getWalletAddress
- increaseVault
- lockBalance
- proposeVote
- selectWeightedHolder
- setCommunityTx
- setContractSourceId
- setState
- setWallet
- transfer
- transferLocked
- unlockVault
- vote
• new default(arweave
, wallet?
, cacheTTL?
)
Before interacting with Community you need to have at least Arweave initialized.
Name | Type | Description |
---|---|---|
arweave |
default |
Arweave instance |
wallet? |
JWKInterface | "use_wallet" |
JWK wallet file data |
cacheTTL |
number |
Refresh interval in milliseconds for the cached state |
▸ create(tags?
): Promise
<string
>
Create a new Community with the current, previously saved (with setState
) state.
Name | Type | Default value | Description |
---|---|---|---|
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The created community transaction ID.
▸ finalize(id
, tags?
): Promise
<string
>
Finalize a vote, to run the desired vote details if approved, or reject it and close.
Name | Type | Default value | Description |
---|---|---|---|
id |
number |
undefined |
The vote ID, this is the index of the vote in votes |
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The transaction ID for this action
▸ get(params?
): Promise
<ResultInterface
>
Do a GET call to any function on the contract.
Name | Type | Description |
---|---|---|
params |
InputInterface |
InputInterface |
Promise
<ResultInterface
>
ResultInterface
▸ getActionCost(inAr?
, options?
): Promise
<string
>
Get the current action (post interaction) cost of a community.
deprecated
use getFee() instead.
Name | Type | Default value | Description |
---|---|---|---|
inAr |
boolean |
false |
Return in winston or AR |
options? |
Object |
undefined |
If return inAr is set to true, these options are used to format the returned AR value. |
options.decimals |
number |
undefined |
- |
options.formatted |
boolean |
undefined |
- |
options.trim |
boolean |
undefined |
- |
Promise
<string
>
▸ getBalance(target?
): Promise
<number
>
Get the target or current wallet token balance
Name | Type | Description |
---|---|---|
target |
string |
The target wallet address |
Promise
<number
>
Current target token balance
▸ getCommunityContract(): Promise
<string
>
Get the current Community contract ID
Promise
<string
>
▸ getContractSourceId(): Promise
<string
>
Get the contract source txid used for new PSCs.
Promise
<string
>
The contract source ID.
▸ getCreateCost(inAr?
, options?
): Promise
<string
>
Get the current create cost of a community.
deprecated
use getFee() instead.
Name | Type | Default value | Description |
---|---|---|---|
inAr |
boolean |
false |
Return in winston or AR |
options? |
Object |
undefined |
If return inAr is set to true, these options are used to format the returned AR value. |
options.decimals |
number |
undefined |
- |
options.formatted |
boolean |
undefined |
- |
options.trim |
boolean |
undefined |
- |
Promise
<string
>
▸ getFee(inAr?
, options?
): Promise
<string
>
Name | Type | Default value |
---|---|---|
inAr |
boolean |
false |
options? |
Object |
undefined |
options.decimal? |
boolean |
undefined |
options.formatted |
boolean |
undefined |
options.trim? |
boolean |
undefined |
Promise
<string
>
▸ getMainContractId(): Promise
<string
>
Get the Main Community contract ID
Promise
<string
>
The main contract ID.
▸ getRole(target?
): Promise
<string
>
Get the target or current wallet role
Name | Type | Description |
---|---|---|
target |
string |
The target wallet address |
Promise
<string
>
Current target role
▸ getState(cached?
): Promise
<StateInterface
>
Get the current Community state.
Name | Type | Default value | Description |
---|---|---|---|
cached |
boolean |
true |
Wether to return the cached version or reload |
Promise
<StateInterface
>
- The current state and sync afterwards if needed.
▸ getUnlockedBalance(target?
): Promise
<number
>
Get the target or current wallet unlocked token balance
Name | Type | Description |
---|---|---|
target |
string |
The target wallet address |
Promise
<number
>
Current target token balance
▸ getVaultBalance(target?
): Promise
<number
>
Get the target or current wallet vault balance
Name | Type | Description |
---|---|---|
target |
string |
The target wallet address |
Promise
<number
>
Current target token balance
▸ getWalletAddress(): Promise
<string
>
Get the current wallet address.
Promise
<string
>
Promise Wallet address
▸ increaseVault(vaultId
, lockLength
, tags?
): Promise
<string
>
Increase the lock time (in blocks) of a vault.
Name | Type | Default value | Description |
---|---|---|---|
vaultId |
number |
undefined |
The vault index position to increase |
lockLength |
number |
undefined |
Length of the lock, in blocks |
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The transaction ID for this action
▸ lockBalance(qty
, lockLength
, tags?
): Promise
<string
>
Lock your balances in a vault to earn voting weight.
Name | Type | Default value | Description |
---|---|---|---|
qty |
number |
undefined |
Positive integer for the quantity to lock |
lockLength |
number |
undefined |
Length of the lock, in blocks |
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The transaction ID for this action
▸ proposeVote(params
, tags?
): Promise
<string
>
Create a new vote
Name | Type | Default value | Description |
---|---|---|---|
params |
VoteInterface |
undefined |
VoteInterface without the "function" |
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The transaction ID for this action
▸ selectWeightedHolder(balances?
, vault?
): Promise
<string
>
Select one of your community holders based on their weighted total balance.
Name | Type | Description |
---|---|---|
balances |
BalancesInterface |
State balances, optional. |
vault |
VaultInterface |
State vault, optional. |
Promise
<string
>
▸ setCommunityTx(txId
): Promise
<boolean
>
Set the Community interactions to this transaction ID.
Name | Type | Description |
---|---|---|
txId |
string |
Community's Transaction ID |
Promise
<boolean
>
boolean - True if successful, false if error.
▸ setContractSourceId(id
): Promise
<boolean
>
Update the used contract source transaction ID.
Name | Type | Description |
---|---|---|
id |
string |
New contract source ID. |
Promise
<boolean
>
boolean that validates if the update was done.
▸ setState(name
, ticker
, balances
, quorum?
, support?
, voteLength?
, lockMinLength?
, lockMaxLength?
, vault?
, votes?
, roles?
, extraSettings?
): Promise
<StateInterface
>
Set the states for a new Community using the Community contract.
Name | Type | Default value | Description |
---|---|---|---|
name |
string |
undefined |
The Community name |
ticker |
string |
undefined |
Currency ticker, ex: TICK |
balances |
BalancesInterface |
undefined |
an object of wallet addresses and their token balances |
quorum |
number |
50 |
% of votes weight, for a proposal to be valid |
support |
number |
50 |
= % of votes as "yes", for a vote to be valid |
voteLength |
number |
2000 |
For how long (in blocks) should the vote be active |
lockMinLength |
number |
720 |
What is the minimum lock time (in blocks) |
lockMaxLength |
number |
10000 |
What is the maximum lock time (in blocks) |
vault |
VaultInterface |
{} |
Vault object, optional |
votes |
VoteInterface [] |
[] |
Votes, optional |
roles |
RoleInterface |
{} |
Roles, optional |
extraSettings |
[string , any ][] |
[] |
Any custom extra settings can be sent here. @since v1.1.0 |
Promise
<StateInterface
>
- The created state
▸ setWallet(wallet
, address?
): Promise
<string
>
Set the user wallet data.
Name | Type | Description |
---|---|---|
wallet |
JWKInterface | "use_wallet" |
JWK wallet file data |
address? |
string |
- |
Promise
<string
>
The wallet address
▸ transfer(target
, qty
, tags?
): Promise
<string
>
Transfer token balances to another account.
Name | Type | Default value | Description |
---|---|---|---|
target |
string |
undefined |
Target Wallet Address |
qty |
number |
undefined |
Amount of the token to send |
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The transaction ID for this action
▸ transferLocked(target
, qty
, lockLength
, tags?
): Promise
<string
>
Transfer tokens to an account's vault.
Name | Type | Default value | Description |
---|---|---|---|
target |
string |
undefined |
Target Wallet Address |
qty |
number |
undefined |
Amount of the token to send |
lockLength |
number |
undefined |
For how many blocks to lock the tokens |
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The transaction ID for this action
▸ unlockVault(tags?
): Promise
<string
>
Unlock all your locked balances that are over the lock period.
Name | Type | Default value | Description |
---|---|---|---|
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The transaction ID for this action
▸ vote(id
, cast
, tags?
): Promise
<string
>
Cast a vote on an existing, and active, vote proposal.
Name | Type | Default value | Description |
---|---|---|---|
id |
number |
undefined |
The vote ID, this is the index of the vote in votes |
cast |
"yay" | "nay" |
undefined |
Cast your vote with 'yay' (for yes) or 'nay' (for no) |
tags |
TagInterface [] |
[] |
optional: tags to be added to this transaction |
Promise
<string
>
The transaction ID for this action