Updated: added full code below.
I'm trying to run the "Creating a payment transaction" example but the error I get is
const account = await server.loadAccount(sourcePublicKey);
^^^^^
SyntaxError: await is only valid in async function
I am running this on Ubuntu 18.04 (Digital Ocean) w/ Node.js v8.10 as instructed and have edited the code so that it uses the test network and key pairs I have set up w/ the laboratory.
So what do I need to do to my setup to get this example to work, or is there a workaround using promise? I just want to do a test transfer of some lumens on the test network.
Here's the full code - it's the same as what is provided as example code on the stellar developer site at link above. (The secret key is for a testnet address so I don't mind sharing it).
const StellarSdk = require('stellar-sdk');
const sourceSecretKey = 'SC5XS6G54A2ILNQRZF4H2MF57CPOWFNLPGGVD5NTJ7FDJA2VACTLFR7N';
const sourceKeypair = StellarSdk.Keypair.fromSecret(sourceSecretKey);
const sourcePublicKey = sourceKeypair.publicKey();
console.log('\nPublic Key derived = ');
console.log(sourcePublicKey);
const receiverPublicKey = 'GC6AESSU7M35TQEFUIVUW2G7375G5YRLIPIT7WDSJRLT5UMLI5P76F2S';
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
StellarSdk.Network.useTestNetwork();
const account = await server.loadAccount(sourcePublicKey);
const fee = await server.fetchBaseFee();
const transaction = new StellarSdk.TransactionBuilder(account, { fee })
.addOperation(StellarSdk.Operation.payment({
destination: receiverPublicKey,
asset: StellarSdk.Asset.native(),
amount: '350.1234567',
}))
.setTimeout(30)
.build();
transaction.sign(sourceKeypair);
console.log(transaction.toEnvelope().toXDR('base64'));
try {
const transactionResult = await server.submitTransaction(transaction);
console.log(JSON.stringify(transactionResult, null, 2));
console.log('\nSuccess! View the transaction at: ');
console.log(transactionResult._links.transaction.href);
} catch (e) {
console.log('An error has occured:');
console.log(e);
}