EQUILIBRIUM API
API bindings to access Equilibruim substrate queries and transactions
NOTE Typescript bindings included
Installation
$ npm i --save @equilab/api
$ yarn add @equilab/api
Usage
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");
})();
createApi("wss://alice.tge-testnet-release.equilibrium.io")
.then(api => api.getBalance("YOUR_ADDRESS", "EQ"))
.then(balance => console.log(balance.toJSON()));
Methods
api.setSigner(signer: Signer)
sets transaction signer, can be used with injected wallet
api.multi(...) - useful for subscribing to multiple queries
api.claim(address: string, signature: string)
create claim transaction
import { createApi } from "@equilab/api";
import { u8aToHex } from "@polkadot/util";
import { decodeAddress } from "@polkadot/util-crypto";
import Web3 from "web3";
const polkadotAddress = "5DnoYz3koaRcMZ9Hj4FmQ2nNRKQfS73yBmEzzM9SsPn9cLtb";
const ethAddress = "0xE372d786E3E6529BBe9CeA4040466531E2Ac4796";
const web3 = new Web3(Web3.givenProvider);
const message = `Pay EQ to the account:${u8aToHex(decodeAddress(account.address), -1, false)}`;
Promise.all([
createApi("wss://alice.tge-testnet-release.equilibrium.io"),
web3.current.eth.personal.sign(message, ethAddress)
]).then(([api, message]) => api.claim(polkadotAddress, sig).send() )
api.vest()
claim unlocked vested amount for current address
createApi(...).then(api => api.vest().signAndSend(YOUR_ADDRESS))
api.getBalance(address: string, currency)
query balance, NOTE you can call multi to subscribe to multiple address or currencies balance change
const subscribeToEQBalances = async (...addresses: string[]) => {
const api = await createAPI(NODE);
const unsub = await api.getBalance.multi(
addresses.map(address => [address, "EQ"]),
(balances) => console.log(balances)
);
return unsub;
}
*api.transfer(currency: "Usd" | "EQ" | "Eth" | "Btc" | "Eos" | "Dot", to: string | Uint8Array | AccountId, amount: string | number )
transfer amount of currency to address
import { createApi } from "@equilab/api";
(async () => {
const api = await createApi("wss://api.mvp.equilibrium.io");
await api.transfer(
"EQ",
"5DnoYz3koaRcMZ9Hj4FmQ2nNRKQfS73yBmEzzM9SsPn9cLtb",
"1000000000"
);
})();
Other
- api.getClaim
- api.getClaimSigning
- api.getClaimVesting
- api.getTotalClaim
- api.getVested
- api.getVesting