EQUILIBRIUM API
API bindings to access Equilibruim substrate queries and transactions
NOTE Typescript bindings included
Getting started
$ npm i --save @equilab/api
$ yarn add @equilab/api
Usage
API Init
Use createApi(node: string) factory from @equilab/api package
import { createApi } from "@equilab/api";
(async () => {
const api = await createApi("wss://alice.tge-testnet-release.equilibrium.io");
const balance = await api.getBalance("YOUR_ADDRESS", "EQ");
console.log(balance.toJSON());
})();
createApi("wss://alice.tge-testnet-release.equilibrium.io")
.then(api => api.getBalance("YOUR_ADDRESS", "EQ"))
.then(balance => console.log(balance.toJSON()));
API Methods
getAccounts(): Promise<string[]>
Fetch list of addresses in system
getBlockHash(blockNumber: number): Promise<Hash>
Fetch hash of block by its number
subscribeNewBlockHeads(blockHandler: (header: BlockHeader) => Promise<void>> | void): UnsubscribePromise
Retrieves the best finalized header via subscription
setSigner(signer: Signer): void
Sets transaction signer, can be used with injected wallet
multi(calls: QueryableStorageMultiArg<"promise">[], callback: (result: Codec[]) => void | Promise<void>): UnsubscribePromise
Allows for the querying of multiple storage entries and the combination thereof into a single result. This is a very optimal way to make multiple queries since it only makes a single connection to the node and retrieves the data over one subscription. Refer to multiple queries section of polkadot.js api docs
getNonce(address: string): Promise<Index>
Fetch next available nonce for this address
API Storage queries
Storage queries are compliant with Polkadot.JS storage interfaces
getBalance(key1: AccountId, key2: Currency): Promise<SignedBalance>
getRate(key: Currency): Promise<PricePoint>
getPrices(key1: Currency, key2: PricePeriod): Promise<Vec>
getVested(key: AccountId): Promise<BalanceOf>
getVesting(key: AccountId): Promise<VestingInfo>
Information regarding the vesting of a given account.
getClaim(key: EthereumAddress): Promise<BalanceOf>
getClaimSigning(key: EthereumAddress): Promise<bool>
The statement kind that must be signed, if any.
getClaimVesting(key: EthereumAddress): Promise<(BalanceOf,BalanceOf,BlockNumber)>
Vesting schedule for a claim.
First balance is the total amount that should be held for vesting.
Second balance is how much should be unlocked per block.
The block number is when the vesting should start.
getTotalClaim(): Promise<BalanceOf>
hasGroup(key1: UserGroup, key2: AccountId): Promise<bool>
aggregatesByGroup(key1: UserGroup, key2: Currency): Promise<TotalAggregates>
API Transaction methods
Transaction methods are compliant with Polkadot.JS transaction interfaces
setBailsman(isBailsman: boolean): SubmittableExtrinsic
Sets the bailsman group to the sender account
transfer(currency: Currency,to: AccountId,value: Balance,): SubmittableExtrinsic
sudo(call: Call,): SubmittableExtrinsic
Authenticates the sudo key and dispatches a function call with Root
origin.
The dispatch origin for this call must be Signed.
- O(1).
- Limited storage reads.
- One DB write (event).
- Weight of derivative
call
execution + 10,000.
setPrice(currency: Currency,price: FixedI64,): SubmittableExtrinsic
vest(): SubmittableExtrinsic
Unlock any vested funds of the sender account.
The dispatch origin for this call must be Signed and the sender must have funds still
locked under this module.
Emits either VestingCompleted
or VestingUpdated
.
O(1)
.- DbWeight: 2 Reads, 2 Writes
- Reads: Vesting Storage, Balances Locks, [Sender Account]
- Writes: Vesting Storage, Balances Locks, [Sender Account]
- Benchmark:
- Unlocked: 48.76 + .048 * l µs (min square analysis)
- Locked: 44.43 + .284 * l µs (min square analysis)
- Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
vestTo(target: LookupSource,): SubmittableExtrinsic
Unlock any vested funds of a target
account.
The dispatch origin for this call must be Signed.
target
: The account whose vested funds should be unlocked. Must have funds still
locked under this module.
Emits either VestingCompleted
or VestingUpdated
.
O(1)
.- DbWeight: 3 Reads, 3 Writes
- Reads: Vesting Storage, Balances Locks, Target Account
- Writes: Vesting Storage, Balances Locks, Target Account
- Benchmark:
- Unlocked: 44.3 + .294 * l µs (min square analysis)
- Locked: 48.16 + .103 * l µs (min square analysis)
- Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
claim(dest: AccountId,ethereum_signature: EcdsaSignature,): SubmittableExtrinsic
Make a claim to collect your DOTs.
The dispatch origin for this call must be None.
Unsigned Validation:
A call to claim is deemed valid if the signature provided matches
the expected signed message of:
Ethereum Signed Message:
(configured prefix string)(address)
and address
matches the dest
account.
Parameters:
dest
: The destination account to payout the claim.ethereum_signature
: The signature of an ethereum signed message
matching the format described above.
The weight of this call is invariant over the input parameters.
- One `eth_recover` operation which involves a keccak hash and a
ecdsa recover.
- Three storage reads to check if a claim exists for the user, to
get the current pot size, to see if there exists a vesting schedule.
- Up to one storage write for adding a new vesting schedule.
- One `deposit_creating` Currency call.
- One storage write to update the total.
- Two storage removals for vesting and claims information.
- One deposit event.
Total Complexity: O(1)
Base Weight: 269.7 µs
DB Weight:
-
Read: Signing, Claims, Total, Claims Vesting, Vesting Vesting, Balance Lock, Account
-
Write: Vesting Vesting, Account, Balance Lock, Total, Claim, Claims Vesting, Signing
Validate Unsigned: +188.7 µs
claimAttest(dest: AccountId,ethereum_signature: EcdsaSignature,statement: Bytes,): SubmittableExtrinsic
Make a claim to collect your DOTs by signing a statement.
The dispatch origin for this call must be None.
Unsigned Validation:
A call to claim_attest
is deemed valid if the signature provided matches
the expected signed message of:
Ethereum Signed Message:
(configured prefix string)(address)(statement)
and address
matches the dest
account; the statement
must match that which is
expected according to your purchase arrangement.
Parameters:
dest
: The destination account to payout the claim.ethereum_signature
: The signature of an ethereum signed message
matching the format described above.statement
: The identity of the statement which is being attested to in the signature.
The weight of this call is invariant over the input parameters.
- One `eth_recover` operation which involves a keccak hash and a
ecdsa recover.
- Four storage reads to check if a claim exists for the user, to
get the current pot size, to see if there exists a vesting schedule, to get the
required statement.
- Up to one storage write for adding a new vesting schedule.
- One `deposit_creating` Currency call.
- One storage write to update the total.
- Two storage removals for vesting and claims information.
- One deposit event.
Total Complexity: O(1)
Base Weight: 270.2 µs
DB Weight:
- Read: Signing, Claims, Total, Claims Vesting, Vesting Vesting, Balance Lock, Account
- Write: Vesting Vesting, Account, Balance Lock, Total, Claim, Claims Vesting, Signing
Validate Unsigned: +190.1 µs