How to use the @liskhq/lisk-transactions.TransferTransaction function in @liskhq/lisk-transactions

To help you get started, we’ve selected a few @liskhq/lisk-transactions 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 / app.js View on Github external
app.post('/faucet', function (req, res) {
    const address = req.body.address;
    const amount = req.body.amount;

    const fundTransaction = new transactions.TransferTransaction({
        amount: transactions.utils.convertLSKToBeddows(amount),
        recipientId: address,
    });

    fundTransaction.sign(accounts.sender.passphrase); // Genesis account
    api.transactions.broadcast(fundTransaction.toJSON()).then(response => {
        res.app.locals.payload = {
            res: response.data,
            tx: fundTransaction.toJSON(),
        };
        console.log("++++++++++++++++ API Response +++++++++++++++++");
        console.log(response.data);
        console.log("++++++++++++++++ Transaction Payload +++++++++++++++++");
        console.log(fundTransaction.stringify());
        console.log("++++++++++++++++ End Script +++++++++++++++++");
        res.redirect('/payload');
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 / client / app.js View on Github external
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();

    let tx = new transactions.TransferTransaction({
        amount: '1',
        recipientId: packetCredentials.address,
    });

    tx.sign('wagon stock borrow episode laundry kitten salute link globe zero feed marble'); // Genesis account with address: 16313739661670634666L
    res.render('initialize', { packetCredentials });

    api.transactions.broadcast(tx.toJSON()).then(res => {
        console.log("++++++++++++++++ API Response +++++++++++++++++");
        console.log(res.data);
        console.log("++++++++++++++++ Credentials +++++++++++++++++");
        console.dir(packetCredentials);
        console.log("++++++++++++++++ Transaction Payload +++++++++++++++++");
        console.log(tx.stringify());
        console.log("++++++++++++++++ End Script +++++++++++++++++");
    }).catch(err => {
github LiskHQ / lisk-sdk-examples / transport / client / scripts / create_and_initialize_packet_account.js View on Github external
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();

let tx = new transactions.TransferTransaction({
    amount: '1',
    recipientId: packetCredentials.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("++++++++++++++++ Credentials +++++++++++++++++");
    console.dir(packetCredentials);
    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 / protocol-specs / utils / chain_state_builder.js View on Github external
to: addressTo => {
					const amountBeddows = `${amount * this.fixedPoint}`;

					const transferTx = new TransferTransaction({
						amount: amountBeddows,
						recipientId: Object.values(this.state.accounts).find(
							anAccount => anAccount.address === addressTo,
						).address,
						timestamp: this.timestamp,
					});

					transferTx.sign(
						Object.values(this.state.accounts).find(
							anAccount => anAccount.address === addressFrom,
						).passphrase,
					);
					// Push it to pending transaction
					this.state.pendingTransactions.push(transferTx);
					this.lastTransactionId = transferTx._id;
					return this;
github LiskHQ / lisk-sdk-examples / delivery / client / create_and_initialize_packet_account.js View on Github external
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();

let tx =  new transactions.TransferTransaction({
    amount: '1235',
    recipientId: packetCredentials.address,
});

tx.sign('wagon stock borrow episode laundry kitten salute link globe zero feed marble');

api.transactions.broadcast(tx.toJSON()).then(res => {
    console.log(res.data);
    console.log("+++++++++++++++++++++++++++++++++" );
    console.dir(packetCredentials);
    console.log("+++++++++++++++++++++++++++++++++" );
    console.log("+++++++++++++++++++++++++++++++++" );
    console.log(tx.stringify());
    console.log("+++++++++++++++++++++++++++++++++" );
}).catch(err => { console.log(JSON.stringify(err.errors, null, 2)) });
github LiskHQ / lisk-sdk / protocol-specs / generators / block_processing_second_signature / index.js View on Github external
const generateTestCasesValidBlockSecondSignatureTx = () => {
	const amount = '5500000000';
	const transferObject = {
		amount,
		recipientId: accounts.existingDelegate.address,
		timestamp,
	};

	const transferTx = new TransferTransaction(transferObject);
	transferTx.sign(accounts.genesis.passphrase);

	const block = createBlock(
		defaultConfig,
		initialAccountState,
		genesisBlock,
		1,
		0,
		{
			version: 1,
			transactions: [transferTx],
		},
	);

	const { balance: senderBalance } = initialAccountState.find(
		account => account.address === accounts.genesis.address,
github LiskHQ / lisk-sdk-examples / scripts / create_sendable_transaction.js View on Github external
inputs.timestamp = inputs.timestamp || 0;
	const recipientIdFromPublicKey = recipientPublicKey
		? getAddressFromPublicKey(recipientPublicKey)
		: undefined;

	inputs.recipientId = recipientIdFromPublicKey
		? recipientIdFromPublicKey
		: inputs.recipientId;


	if (!passphrase) {
		throw "Cannot sign a transaction without a passphrase. Specify your passphrase as in the input object (and optional second passphrase)";
	}

	const transferTransaction = new TransferTransaction(
		{
			asset: data ? { data } : {},
			amount,
			fee,
			recipientId,
			senderPublicKey,
			type,
			timestamp,
		}
	);
	transferTransaction.sign(passphrase, secondPassphrase);

	return asJSON(skipUndefined(transferTransaction.toJSON()));
};