Last active
March 6, 2019 04:39
-
-
Save daoka/8cc753471fc0a4ee9339168fe2b307be to your computer and use it in GitHub Desktop.
nem2-sdk(v0.10.2 beta) cow sandbox
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 { Account, NetworkType, TransactionHttp, AddressAliasTransaction, Deadline, AliasType, UInt64, NamespaceId, Address, AliasActionType } from "nem2-sdk"; | |
const privateKey = 'YOUR_PRIVATE_KEY'; | |
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST); | |
const apiServer = 'http://localhost:3000/'; | |
const transactionHttp = new TransactionHttp(apiServer); | |
const namespaceId = new NamespaceId([1937548940, 3993951157]); | |
const linkAddress = Address.createFromRawAddress('SACVJB7HYIJMFMPI4IYN2XJHAN66D7VHMPLUL6ZP'); | |
const addressAliasTransaction = AddressAliasTransaction.create( | |
Deadline.create(), | |
AliasActionType.Link, | |
namespaceId, | |
linkAddress, | |
NetworkType.MIJIN_TEST | |
) | |
const signedTransaction = account.sign(addressAliasTransaction); | |
transactionHttp.announce(signedTransaction).subscribe( | |
x => console.log(x), | |
err => console.error(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
import { Account, NetworkType, TransactionHttp, AddressAliasTransaction, Deadline, AliasType, UInt64, NamespaceId, Address, AliasActionType } from "nem2-sdk"; | |
const privateKey = 'YOUR_PRIVATE_KEY'; | |
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST); | |
const apiServer = 'http://localhost:3000/'; | |
const transactionHttp = new TransactionHttp(apiServer); | |
const namespaceId = new NamespaceId([1937548940, 3993951157]); | |
const linkAddress = Address.createFromRawAddress('SACVJB7HYIJMFMPI4IYN2XJHAN66D7VHMPLUL6ZP'); | |
const addressAliasTransaction = AddressAliasTransaction.create( | |
Deadline.create(), | |
AliasActionType.Unlink, | |
namespaceId, | |
linkAddress, | |
NetworkType.MIJIN_TEST | |
) | |
const signedTransaction = account.sign(addressAliasTransaction); | |
transactionHttp.announce(signedTransaction).subscribe( | |
x => console.log(x), | |
err => console.error(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
import { NamespaceHttp, NamespaceId } from "nem2-sdk"; | |
const apiServer = 'http://localhost:3000/'; | |
const namespaceHttp = new NamespaceHttp(apiServer); | |
const namespaceId = new NamespaceId([1937548940, 3993951157]); | |
// memo: エラーになる... (probably unworked...) | |
// response: Error: Address KAVUH+FCESKX6OIW3V0NA33H/QDJ10X7LW== has to be 40 characters long | |
namespaceHttp.getLinkedAddress(namespaceId).subscribe( | |
x => console.log(x), | |
err => console.log(err) | |
); | |
// response: AddressAlias { type: 2, address: 'kAVUh+fCEsKx6OIw3V0nA33h/qdj10X7Lw==' } | |
namespaceHttp.getNamespace(namespaceId).subscribe( | |
x => console.log(x.alias), | |
err => console.error(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
import { NamespaceHttp, NamespaceId } from "nem2-sdk"; | |
const apiServer = 'http://localhost:3000/'; | |
const namespaceHttp = new NamespaceHttp(apiServer); | |
const namespaceId = new NamespaceId([1937548940, 3993951157]); | |
// memo: Linkされていても空で返ってくる (probably unworked...) | |
// response: MosaicId {} | |
namespaceHttp.getLinkedMosaicId(namespaceId).subscribe( | |
x => console.log(x), | |
err => console.log(err) | |
); | |
// response: MosaicAlias { type: 1, mosaicId: '5975281735037539439' } | |
namespaceHttp.getNamespace(namespaceId).subscribe( | |
x => console.log(x.alias), | |
err => console.error(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
import { Account, NetworkType, TransactionHttp, MosaicDefinitionTransaction, Deadline, MosaicProperties, UInt64, MosaicSupplyChangeTransaction, MosaicSupplyType, AggregateTransaction } from 'nem2-sdk'; | |
import { mosaicId, convert } from 'nem2-library'; | |
const account = Account.createFromPrivateKey('YOUR_PRIVATE_KEY', NetworkType.MIJIN_TEST); | |
const apiServer = 'http://localhost:3000/' | |
const transactionHttp = new TransactionHttp(apiServer); | |
const nonce = [0xE6, 0xDE, 0x84, 0xB8]; | |
const m = mosaicId(nonce, convert.hexToUint8(account.publicKey)); | |
console.log(m); | |
console.log(new UInt64(m)); | |
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( | |
Deadline.create(), | |
new Uint8Array(nonce), | |
new UInt64(m), | |
MosaicProperties.create({supplyMutable: false, transferable: true, levyMutable: false, divisibility: 0, duration: UInt64.fromUint(100)}), | |
NetworkType.MIJIN_TEST | |
); | |
const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( | |
Deadline.create(), | |
mosaicDefinitionTransaction.mosaicId, | |
MosaicSupplyType.Increase, | |
UInt64.fromUint(1000000), | |
NetworkType.MIJIN_TEST | |
); | |
const aggregateTransaction = AggregateTransaction.createComplete( | |
Deadline.create(), | |
[mosaicDefinitionTransaction.toAggregate(account.publicAccount), | |
mosaicSupplyChangeTransaction.toAggregate(account.publicAccount)], | |
NetworkType.MIJIN_TEST, | |
[] | |
); | |
const signTransaction = account.sign(aggregateTransaction); | |
transactionHttp.announce(signTransaction).subscribe( | |
x => console.log(x), | |
err => console.error(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
import { Account, NetworkType, TransactionHttp, MosaicAliasTransaction, Deadline, AliasActionType, NamespaceId, MosaicId } from "nem2-sdk"; | |
import { mosaicId, convert } from "nem2-library"; | |
const privateKey = 'YOUR_PRIVATE_KEY'; | |
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST); | |
const apiServer = 'http://localhost:3000/'; | |
const transactionHttp = new TransactionHttp(apiServer); | |
const nonce = [0xE6, 0xDE, 0x84, 0xA3]; | |
const m = mosaicId(nonce, convert.hexToUint8(account.publicKey)); | |
const namespaceId = new NamespaceId([1937548940, 3993951157]); | |
const mosaicAliasTransaction = MosaicAliasTransaction.create( | |
Deadline.create(), | |
AliasActionType.Link, | |
namespaceId, | |
new MosaicId(m), | |
NetworkType.MIJIN_TEST | |
) | |
const signedTransaction = account.sign(mosaicAliasTransaction); | |
transactionHttp.announce(signedTransaction).subscribe( | |
x => console.log(x), | |
err => console.error(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
import { Account, NetworkType, TransactionHttp, MosaicAliasTransaction, Deadline, AliasActionType, NamespaceId, MosaicId } from "nem2-sdk"; | |
import { mosaicId, convert } from "nem2-library"; | |
const privateKey = 'YOUR_PRIVATE_KEY'; | |
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST); | |
const apiServer = 'http://localhost:3000/'; | |
const transactionHttp = new TransactionHttp(apiServer); | |
const nonce = [0xE6, 0xDE, 0x84, 0xA3]; | |
const m = mosaicId(nonce, convert.hexToUint8(account.publicKey)); | |
const namespaceId = new NamespaceId([1937548940, 3993951157]); | |
const mosaicAliasTransaction = MosaicAliasTransaction.create( | |
Deadline.create(), | |
AliasActionType.Unlink, | |
namespaceId, | |
new MosaicId(m), | |
NetworkType.MIJIN_TEST | |
) | |
const signedTransaction = account.sign(mosaicAliasTransaction); | |
transactionHttp.announce(signedTransaction).subscribe( | |
x => console.log(x), | |
err => console.error(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
import { Account, NetworkType, TransactionHttp, RegisterNamespaceTransaction, Deadline, UInt64 } from "nem2-sdk"; | |
const privateKey = 'YOUR_PRIVATE_KEY'; | |
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST); | |
const apiServer = 'http://localhost:3000/'; | |
const transactionHttp = new TransactionHttp(apiServer); | |
const namespaceName = 'YOUR_NAMESPCAE_NAME'; | |
const nameSpaceTransaction = RegisterNamespaceTransaction.createRootNamespace( | |
Deadline.create(), | |
namespaceName, | |
UInt64.fromUint(500), | |
NetworkType.MIJIN_TEST | |
); | |
const signedTransaction = account.sign(nameSpaceTransaction); | |
transactionHttp.announce(signedTransaction).subscribe( | |
x => console.log(x), | |
err => console.error(err) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment