4

What would be three of the most used lines of code in the JavaScript SDK that could make my wallet perform small actions for me?

closed as too broad by Nekrataal, Henry WH Hack v2.1.3, Helmar, Andrei Savin, Glorfindel Jan 20 '18 at 17:40

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

3

The simplest one, show balances:

server.loadAccount(publicKey)
      .then(function(account) {
          account.balances.forEach(function(balance) {
              // show them
          });
      });

Next in line, show last payments:

server.payments()
      .forAccount(publicKey)
      .limit(20)
      .order('desc')
      .call()
      .then(function(response){
          // show them
      });

And finally, sending payments:

server.loadAccount(publicKey).then(function(sourceAccount) {
    var operation = StellarSdk.Operation.payment({
            destination: targetKey,
            asset: StellarSdk.Asset.native(),
            amount: ''+amount
    });
    var transaction = new StellarSdk.TransactionBuilder(sourceAccount)
        .addOperation(operation)
        .addMemo(StellarSdk.Memo.text('Hello'))
        .build();
    transaction.sign(sourceAccount);
    server.submitTransaction(transaction);
});

There are many more operations you could add to your wallet like setting inflation destination, buy/sell assets in the distributed exchange, etc but these are the basic operations every wallet should have for starters.

Not the answer you're looking for? Browse other questions tagged or ask your own question.