Skip to content

Instantly share code, notes, and snippets.

@xembook
Last active Jan 16, 2021
Embed
What would you like to do?

access and open browser console

http://api-01.ap-northeast-1.testnet.symboldev.network:3000/node/server

embed library to browser

(script = document.createElement('script')).src = 'https://xembook.github.io/nem2-browserify/symbol-sdk-0.23.0.js';
document.getElementsByTagName('head')[0].appendChild(script);

prepare

NODE = 'http://api-01.ap-northeast-1.testnet.symboldev.network:3000';
nem = require("/node_modules/symbol-sdk");

repo = new nem.RepositoryFactoryHttp(NODE);
(async() =>{
  epochAdjustment = await repo.getEpochAdjustment().toPromise();
  generationHash = await repo.getGenerationHash().toPromise();
  networkType = await repo.getNetworkType().toPromise();
  currencies = await repo.getCurrencies().toPromise();
  currencyId = currencies.currency.mosaicId.toHex();
})();

nsRepo = repo.createNamespaceRepository();
txRepo = repo.createTransactionRepository();
receiptRepo = repo.createReceiptRepository();
accountRepo = repo.createAccountRepository();
transactionService = new nem.TransactionService(txRepo, receiptRepo);

wsEndpoint = NODE.replace('http', 'ws') + "/ws";
listener = new nem.Listener(wsEndpoint,nsRepo,WebSocket);

getTx = function(){
  return nem.TransferTransaction.create(
    nem.Deadline.create(epochAdjustment),
    alice.address, 
    [],
    nem.PlainMessage.create('listener test'),
    networkType,
    nem.UInt64.fromUint(100000)
  );
}

create alice,bob and deposit to alice

alice = nem.Account.generateNewAccount(networkType);
bob = nem.Account.generateNewAccount(networkType);
console.log("http://faucet.testnet.symboldev.network/?recipient=" + alice.address.plain() +"&amount=10")

create aggregate transaction and announce

tx = getTx();
feeTx = nem.TransferTransaction.create(
    nem.Deadline.create(epochAdjustment),
    bob.address, 
    [], 
    nem.PlainMessage.create('xembook create account'),
    networkType,
    nem.UInt64.fromUint(100000)
);

aggregateArray = [
  feeTx.toAggregate(alice.publicAccount),
  tx.toAggregate(bob.publicAccount),
]

aggregateTx = nem.AggregateTransaction.createComplete(
    nem.Deadline.create(epochAdjustment),
    aggregateArray,
    networkType,
    [],
    nem.UInt64.fromUint(1000000)
);

signedTx = aggregateTx.signTransactionWithCosignatories(
    alice,
    [bob],
    generationHash,
);

listener.open().then(() => {

  listener.status(alice.address,signedTx.hash).subscribe(x=>console.log(x));
  listener.confirmed(alice.address,signedTx.hash).subscribe(x=>console.log(x));
  txRepo.announce(signedTx)
});

check status after few seconds of announce

console.log(listener.isOpen()); //false
console.log(NODE + "/transactionStatus/" + signedTx.hash);  //Success
console.log("http://explorer.testnet.symboldev.network/transactions/" + signedTx.hash); //exists
@rg911
Copy link

rg911 commented Jan 16, 2021

@xembook, Thanks for reporting this. could you, we spotted an issue, meanwhile could you try use the api-01.us-west-1.testnet.symboldev.network node?

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