This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Transactionをブロードキャストしてネットワークへ公開する | |
nem.model.transactions.send(common, transactionEntity, endpoint).then(sendRes => { | |
console.log('sendRes:', sendRes); | |
}).catch(sendErr => { | |
console.log('sendError:', sendErr); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 署名をしてTransactionを送信する準備を完了する | |
const transactionEntity = nem.model.transactions.prepare('mosaicTransferTransaction')(common, transferTransaction, mosaicDefinitionMetaDataPair, nem.model.network.data.testnet.id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 手数料を正確に計算するためにモザイクの定義を取得する | |
let mosaicDefinitionMetaDataPair = nem.model.objects.get('mosaicDefinitionMetaDataPair'); | |
nem.com.requests.namespace.mosaicDefinitions(endpoint, yourMosaic.mosaicId.namespaceId).then(res => { | |
// モザイク定義を取得してモザイク定義オブジェクトへ格納する | |
const neededDefinition = nem.utils.helpers.searchMosaicDefinitionArray(res.data, [yourMosaicName]); | |
// モザイク定義オブジェクトで使用するため、モザイクの名前を取得 | |
const fullMosaicName = nem.utils.format.mosaicIdToName(yourMosaic.mosaicId); | |
// モザイクの存在確認 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// XEM mosaicを付与する | |
// 1000000で1XEMとなります | |
const xemMozaic = nem.model.objects.create('mosaicAttachment')('nem', 'xem', sendAmount * 1000000); | |
transferTransaction.mosaics.push(xemMozaic); | |
// 送りたいXEM以外のmosaicを付与する | |
const yourMosaic = nem.model.objects.create('mosaicAttachment')(yourMosaicNamespace, yourMosaicName, 10000); | |
transferTransaction.mosaics.push(yourMosaic); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 送金先のアドレス | |
const toAddress = 'TAHPGS7CKZAERDU5RGHRCGN4DYGXRLQXO5CPNWIP'; | |
// 送金額 | |
const sendAmount = 1; | |
// 送金の際に指定するメッセージ(空文字でも可) | |
const sendMsg = 'Hello World!'; | |
// Transactionの作成 | |
let transferTransaction = nem.model.objects.create('transferTransaction')(toAddress, sendAmount, sendMsg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 自分の送金したい先のアドレスに変更してください | |
// 送金先のアドレス |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 送金元のパスワード | |
const password = ''; | |
// 送金元の秘密鍵 | |
const privateKey = ''; | |
// パスワードと秘密鍵をセットにしたオブジェクト | |
const common = nem.model.objects.create('common')(password, privateKey); | |
// 署名をしてTransactionを送信する準備を完了する | |
const transactionEntity = await nem.model.transactions.prepare('transferTransaction')(common, transferTransaction, nem.model.network.data.testnet.id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 自分の送金したい先のアドレスに変更してください | |
// 送金先のアドレス |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Transactionをブロードキャストしてネットワークへ公開する | |
nem.model.transactions.send(common, transactionEntity, endpoint).then(res => { | |
console.log('txRes:', res); | |
}).catch(err => { | |
console.log('txErr:', err); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 送金先のアドレス | |
const toAddress = 'TAHPGS7CKZAERDU5RGHRCGN4DYGXRLQXO5CPNWIP'; | |
// 送金額 | |
const sendAmount = 1; | |
// 送金の際に指定するメッセージ(空文字でも可) | |
const sendMsg = 'Hello World!'; | |
// Transactionの作成 | |
const transferTransaction = nem.model.objects.create('transferTransaction')(toAddress, sendAmount, sendMsg); |