Skip to content

Instantly share code, notes, and snippets.

@joeneldeasis
Created November 30, 2019 13:07
Show Gist options
  • Save joeneldeasis/00deae4d0a7bf34c898014d1a0ec6163 to your computer and use it in GitHub Desktop.
Save joeneldeasis/00deae4d0a7bf34c898014d1a0ec6163 to your computer and use it in GitHub Desktop.
Mosaic Transfer
import {
MosaicId,
UInt64,
Address,
TransferTransaction,
Deadline,
Account,
NetworkType,
Mosaic,
TransactionHttp,
PlainMessage,
} from "tsjs-xpx-chain-sdk";
const amount = 100;
const privateKey = "private-key-here" //put your private key here
const toAddress = "VBHYO3-4QPRVF-QI4DVA-BWWEHK-BK2GWZ-RBOCFH-CFBJ" //put your address here
const networkGenerationHash = "56D112C98F7A7E34D1AEDC4BD01BC06CA2276DD546A93E36690B785E82439CA9";
const httpNode = "https://bctestnet3.brimstone.xpxsirius.io";
const transactionHttp = new TransactionHttp(httpNode);
const sender = Account.createFromPrivateKey(privateKey, NetworkType.TEST_NET);
const recipient = Address.createFromRawAddress(toAddress);
const transferTransaction = TransferTransaction.create(
Deadline.create(),
recipient,
[new Mosaic(new MosaicId("25446640478c3b84"), UInt64.fromUint(amount))],
PlainMessage.create("mosaic transfer"),
NetworkType.TEST_NET
);
const signedTransaction = sender.sign(transferTransaction, networkGenerationHash);
transactionHttp.announce(signedTransaction);
console.log("tx: ", signedTransaction);
@joeneldeasis
Copy link
Author

For javascript:

const sdk = require("tsjs-xpx-chain-sdk");

const amount = 100;
const privateKey = "private-key-here"; //put your private key here

const toAddress = "VBHYO3-4QPRVF-QI4DVA-BWWEHK-BK2GWZ-RBOCFH-CFBJ"; //put your address here

const networkGenerationHash = "56D112C98F7A7E34D1AEDC4BD01BC06CA2276DD546A93E36690B785E82439CA9";
const httpNode = "https://bctestnet3.brimstone.xpxsirius.io";
const transactionHttp = new sdk.TransactionHttp(httpNode);

const sender = sdk.Account.createFromPrivateKey(privateKey, sdk.NetworkType.TEST_NET);

const recipient = sdk.Address.createFromRawAddress(toAddress);

const transferTransaction = sdk.TransferTransaction.create(
  sdk.Deadline.create(),
  recipient,
  [new sdk.Mosaic(new sdk.MosaicId("25446640478c3b84"), sdk.UInt64.fromUint(amount))], //change the mosaic id
  sdk.PlainMessage.create("mosaic transfer"),
  sdk.NetworkType.TEST_NET
);

const signedTransaction = sender.sign(transferTransaction, networkGenerationHash);

transactionHttp.announce(signedTransaction);

console.log("tx hash: ", signedTransaction.hash);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment