Skip to content

Instantly share code, notes, and snippets.

@daiki44
Created September 8, 2018 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daiki44/3b5d35f513ff6c5d6ead8f3dc3123174 to your computer and use it in GitHub Desktop.
Save daiki44/3b5d35f513ff6c5d6ead8f3dc3123174 to your computer and use it in GitHub Desktop.
【NEM】NEM-sdk を使って特定アドレスへ XEM を送金する ref: https://daiki-sekiguchi.com/2018/09/07/nem-sdk-transactions-send/
import nem from 'nem-sdk';
// EndpointをTestnetに指定します
// 第1引数はTestnet用のデフォルトのノード
// 第2引数はデフォルトのポート(7890)
const endpoint = nem.model.objects.create('endpoint')(nem.model.nodes.defaultTestnet, nem.model.nodes.defaultPort);
async function main() {
// TODO: 自分の送金したい先のアドレスに変更してください
// 送金先のアドレス
const toAddress = 'TAHPGS7CKZAERDU5RGHRCGN4DYGXRLQXO5CPNWIP';
// 送金額
const sendAmount = 1;
// 送金の際に指定するメッセージ(空文字でも可)
const sendMsg = 'Hello World!';
// TODO: 自分の送金元ウォレットのパスワードを入力してください
// 送金元ウォレットのパスワード
const password = '';
// TODO: 自分の送金元の秘密鍵を入力してください
// 送金元の秘密鍵
const privateKey = '';
// パスワードと秘密鍵をセットにしたオブジェクト
const common = nem.model.objects.create('common')(password, privateKey);
// Transactionの作成
const transferTransaction = nem.model.objects.create('transferTransaction')(toAddress, sendAmount, sendMsg);
// 署名をしてTransactionを送信する準備を完了する
const transactionEntity = await nem.model.transactions.prepare('transferTransaction')(common, transferTransaction, nem.model.network.data.testnet.id);
console.log('txEntity:', transactionEntity);
// Transactionをブロードキャストしてネットワークへ公開する
nem.model.transactions.send(common, transactionEntity, endpoint).then(res => {
console.log('txRes:', res);
}).catch(err => {
console.log('txErr:', err);
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment