How to use the @liskhq/lisk-api-client.APIClient function in @liskhq/lisk-api-client

To help you get started, we’ve selected a few @liskhq/lisk-api-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LiskHQ / lisk-sdk-examples / transport / client / scripts / send_token.js View on Github external
const transactions = require('@liskhq/lisk-transactions');
const cryptography = require('@liskhq/lisk-cryptography');
const { APIClient } = require('@liskhq/lisk-api-client');
const { Mnemonic } = require('@liskhq/lisk-passphrase');
const accounts = require('./accounts.json');

const api = new APIClient(['http://localhost:4000']);

let tx = new transactions.TransferTransaction({
    amount: `${transactions.utils.convertLSKToBeddows('2000')}`,
    recipientId: accounts.carrier.address,
});

tx.sign('wagon stock borrow episode laundry kitten salute link globe zero feed marble'); // Genesis account with address: 16313739661670634666L

api.transactions.broadcast(tx.toJSON()).then(res => {
    console.log("++++++++++++++++ API Response +++++++++++++++++");
    console.log(res.data);
    console.log("++++++++++++++++ Transaction Payload +++++++++++++++++");
    console.log(tx.stringify());
    console.log("++++++++++++++++ End Script +++++++++++++++++");
}).catch(err => {
    console.log(JSON.stringify(err.errors, null, 2));
github LiskHQ / lisk-sdk-examples / transport / iot / light_alarm / index.js View on Github external
const PIN = require("rpi-pins");
const GPIO = new PIN.GPIO();
// Rpi-pins uses the WiringPi pin numbering system (check https://pinout.xyz/pinout/pin16_gpio23)
GPIO.setPin(4, PIN.MODE.INPUT);
const LightAlarmTransaction = require('./light-alarm');
const { APIClient } = require('@liskhq/lisk-api-client');

// Enter here the IP of the node you want to reach for API requests
// Check the IP by running `ifconfig` inside your local terminal
const api = new APIClient(['http://localhost:4000']);

// Check config file or curl localhost:4000/api/node/constants to verify your epoc time (OK when using /transport/node/index.js)
const dateToLiskEpochTimestamp = date => (
    Math.floor(new Date(date).getTime() / 1000) - Math.floor(new Date(Date.UTC(2016, 4, 24, 17, 0, 0, 0)).getTime() / 1000)
);

/* Note: Always update to the package you are using */
const packetCredentials = { /* Insert packet credentials here (retrieved from "Initialize" page of the client app) */};

setInterval(() => {
	let state = GPIO.read(4);
	if(state === 0) {
		console.log('Package has been opened! Send lisk transaction!');
		// Uncomment the below code in step 1.3 of the workshop
        /*let tx =  new LightAlarmTransaction({
            timestamp: dateToLiskEpochTimestamp(new Date())
github LiskHQ / lisk-sdk-examples / transport / client / app.js View on Github external
const accounts = require('../client/accounts.json');
const RegisterPacketTransaction = require('../transactions/register-packet');
const LightAlarmTransaction = require('../transactions/light-alarm');
const StartTransportTransaction = require('../transactions/start-transport');
const FinishTransportTransaction = require('../transactions/finish-transport');
const transactions = require('@liskhq/lisk-transactions');
const cryptography = require('@liskhq/lisk-cryptography');
const { Mnemonic } = require('@liskhq/lisk-passphrase');

// Constants
const API_BASEURL = 'http://localhost:4000';
const PORT = 3000;

// Initialize
const app = express();
const api = new APIClient([API_BASEURL]);

app.locals.payload = {
    tx: null,
    res: null,
};

// Configure Express
app.set('view engine', 'pug');
app.use(express.static('public'));

// parse application/json
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

/* Utils */
const dateToLiskEpochTimestamp = date => (
github LiskHQ / lisk-sdk-examples / transport / client / scripts / create_and_initialize_packet_account.js View on Github external
const transactions = require('@liskhq/lisk-transactions');
const cryptography = require('@liskhq/lisk-cryptography');
const { APIClient } = require('@liskhq/lisk-api-client');
const { Mnemonic } = require('@liskhq/lisk-passphrase');

const api = new APIClient(['http://localhost:4000']);

/**
 * Util function for creating credentials object.
 *
 * @param {Object} credentials
 * @param {string} credentials.address
 * @param {string} credentials.passphrase
 * @param {string} credentials.publicKey
 * @param {string} credentials.privateKey
 */
const getPacketCredentials = () => {
    const passphrase = Mnemonic.generateMnemonic();
    const keys = cryptography.getPrivateAndPublicKeyFromPassphrase(
        passphrase
    );
    const credentials = {
github LiskHQ / lisk-sdk / commander / src / utils / api.ts View on Github external
export const getAPIClient = ({
	nodes,
	network,
}: APIClientOptions): APIClient => {
	const nethash = NETHASHES[network] || network;
	const clientNodes = nodes && nodes.length > 0 ? nodes : seedNodes[network];

	return new APIClient(clientNodes, { nethash });
};
github LiskHQ / lisk-sdk-examples / delivery / client / create_and_initialize_packet_account.js View on Github external
const transactions = require('@liskhq/lisk-transactions');
const cryptography = require('@liskhq/lisk-cryptography');
const { APIClient } = require('@liskhq/lisk-api-client');
const { Mnemonic } = require('@liskhq/lisk-passphrase');

const api = new APIClient(['http://localhost:4000']);

const getPacketCredentials = () => {
    const passphrase = Mnemonic.generateMnemonic();
    const keys = cryptography.getPrivateAndPublicKeyFromPassphrase(
        passphrase
    );
    const credentials = {
        address: cryptography.getAddressFromPublicKey(keys.publicKey),
        passphrase: passphrase,
        publicKey: keys.publicKey,
        privateKey: keys.privateKey
    };
    return credentials;
};

const packetCredentials = getPacketCredentials();

@liskhq/lisk-api-client

An API client for the Lisk network

Apache-2.0
Latest version published 8 months ago

Package Health Score

50 / 100
Full package analysis