0.10.0 • Published 11 days ago
accumulate.js v0.10.0
Accumulate JavaScript SDK
This is the Accumulate JavaScript SDK built on the Accumulate JSON RPC API.
Installation
# Yarn
$ yarn add accumulate.js
# npm
$ npm install --save accumulate.js
Usage
For more usage examples see the file test-it/client.test.ts
.
Quick start tutorial
Demo of some of the main APIs of Accumulate:
import { api_v2, ED25519Key, Signer } from "accumulate.js";
const client = new api_v2.Client("https://mainnet.accumulatenetwork.io/v2");
// Generate a random Signer (this is only local, until that account receive its first tokens)
const lid = await Signer.forLite(await ED25519Key.generate());
// Request some ACME token to get started from the faucet
let res = await client.faucet(lid.url.join("ACME"));
await client.waitOnTx(res.txid.toString());
// check the ACME token balance
console.log(await client.queryUrl(lid.url.join("ACME")));
// Convert some tokens into credits necessary to perform operations on Accumulate
const oracle = await client.queryAcmeOracle();
const addCredits = {
recipient: lid.url,
amount: 1000 * 1e8,
oracle,
};
res = await client.addCredits(lid.url.join("ACME"), addCredits, lid);
await client.waitOnTx(res.txid.toString());
// check the credits balance
console.log(await client.queryUrl(lid.url));
// Send some tokens to another random Lite ACME token Account
const recipient = await Signer.forLite(await ED25519Key.generate());
const sendTokens = { to: [{ url: recipient.url.join("ACME"), amount: 12 }] };
res = await client.sendTokens(lid.url.join("ACME"), sendTokens, lid);
await client.waitOnTx(res.txid.toString());
// Now with the credits we can create an Accumulate Digital Identifier (ADI)
// which is one of the fundamental feature of the network
const identitySigner = await ED25519Key.generate(); // Root signer that will control the identity
const identityUrl = "acc://my-own-identity.acme";
const bookUrl = identityUrl + "/my-book";
const createIdentity = {
url: identityUrl,
keyHash: identitySigner.address.publicKeyHash,
keyBookUrl: bookUrl,
};
res = await client.createIdentity(lid.url, createIdentity, lid);
await client.waitOnTx(res.txid.toString());
// check your identity
console.log(await client.queryUrl(identityUrl));
// Instantiate a PageSigner that can now sign transactions on behalf of this identity
// (after receiving credits on the identity initial key page)
const keyPageUrl = bookUrl + "/1";
const addCredits2 = {
recipient: keyPageUrl,
amount: 1000 * 1e8,
oracle,
};
res = await client.addCredits(lid.url.join("ACME"), addCredits2, lid);
await client.waitOnTx(res.txid.toString());
const identityKeyPage = await Signer.forPage(keyPageUrl, identitySigner);
Manually building and signing a transaction
// You need to import the Payload class for the type of transaction you want to make.
// Here we are building a SendTokens transaction.
import { api_v2, ED25519Key, Signer } from "accumulate.js";
import { SendTokens, Transaction, TransactionHeader } from "accumulate.js/core";
import { Envelope } from "accumulate.js/messaging";
const sender = await Signer.forLite(await ED25519Key.generate());
// Build the Payload
const recipient = await Signer.forLite(await ED25519Key.generate());
const amount = 10;
const body = new SendTokens({ to: [{ url: recipient.url.join("ACME"), amount: amount }] });
// Build the transaction header with the transaction principal
// and optionally a timestamp, memo or metadata.
const header = new TransactionHeader({ principal: sender.url.join("ACME") });
// Finally build the (unsigned yet) transaction
const tx = new Transaction({ body, header });
// Sign with a key pair or manually sign with custom key store, Ledger, etc
const sig = await sender.sign(tx, { timestamp: Date.now() });
const env = new Envelope({ transaction: [tx], signatures: [sig] });
// Submit the envelope
const client = new api_v2.Client("https://mainnet.accumulatenetwork.io/v2");
const res = await client.execute(env);
await client.waitOnTx(res.txid.toString());
0.10.0
11 days ago
0.8.8
10 months ago
0.9.3
7 months ago
0.8.7
10 months ago
0.8.6
10 months ago
0.8.6-alpha.1
10 months ago
0.8.6-alpha.2
10 months ago
0.9.0
9 months ago
0.8.6-alpha.5
10 months ago
0.8.6-alpha.6
10 months ago
0.9.2
7 months ago
0.8.6-alpha.3
10 months ago
0.9.1
9 months ago
0.8.6-alpha.4
10 months ago
0.8.6-alpha.7
10 months ago
0.8.6-alpha.8
10 months ago
0.8.5
11 months ago
0.8.4
11 months ago
0.8.3
11 months ago
0.7.4
11 months ago
0.8.2
11 months ago
0.8.1
1 year ago
0.8.0
1 year ago
0.7.3
1 year ago
0.3.0
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.7.2
2 years ago
0.7.1
2 years ago
0.5.0
2 years ago
0.4.0
2 years ago
0.3.1
2 years ago
0.7.0
2 years ago
0.6.0
2 years ago
0.1.5
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago