2

I am trying to successfully send a transaction but its failing whats the purpose of these two functions

1 - StellarSdk.Operation.createAccount

2 - StellarSdk.Operation.payment

if I am using an offline PC to generate the transaction how do I get the sequence number ?

var StellarSdk = require('stellar-sdk')
var wallet = require('./wallet')

StellarSdk.Network.useTestNetwork();
var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');

var secretString = wallet.get_secret('ADDRESS_THAT_HAS_FUNDS');

// create an Account object using locally tracked sequence number
var an_account = new StellarSdk.Account("ADDRESS_THAT_HAS_FUNDS", "WHATS THE SEQUENCE NUMBER");
var transaction = new StellarSdk.TransactionBuilder(an_account)
    .addOperation(StellarSdk.Operation.createAccount({
      destination: "SEND_TO_AN_ADDRESS_THAT_DOESNT_HAVE_FUNDS",
      startingBalance: "1200",  // in XLM
      asset: StellarSdk.Asset.native(),
    }))
    .build();

transaction.sign(StellarSdk.Keypair.fromSecret(secretString)); // sign 
3

createAccount is an operation that you can include in a transaction. It works like a payment from your account to the account specified in the operation. But it has a side-effect of creating the destination account. As such, it will only succeed if the account doesn't already exist and the payment amount is greater than the reserve balance.

payment is also an operation that pays from your account to the specified account. However it only succeeds if the destination account already exists.

By being explicit about whether a payment is creating an account or not we can avoid accidentally sending tokens to the wrong address in most cases.

When an account is created, the sequence number for that account is generated on the network. At some stage you will need to be connected to know what the sequence number is. (But you also need to be connected to create the account, so it's probably not that much of a problem). Once you know the sequence number, you know that it must increase by one for each transaction. If you are creating a batch of n transactions offline then each transaction should have a sequence number of lastSeqNum + n.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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