Oh, sorry, I just realized that part of my code doesn't make sense, because it uses another internal function.
Full working example now:
const request = require('request-promise');
const StellarSdk = require('stellar-sdk');
const pair = StellarSdk.Keypair.random();
console.log(pair.secret(), pair.publicKey());
request({
url: 'https://horizon-testnet.stellar.org/friendbot',
qs: { addr: pair.publicKey() },
json: true
})
.then(function() {
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
server.loadAccount(pair.publicKey())
.then(function(account) { console.log(account); });
});
If it gives you bad_seq error, just try again, it's normal for friendbot to fail sometimes