2

I am new to stellar so please bear with my question if it sounds too basic. So, using the stellar laboratory, I created two accounts lets name 1 and 2. I funded the 1st account with test-net coins using friend-bot and left the 2nd account empty. Now as I understand that an account to be active on stellar network, it should have a minimum balance of about 1XLM. So using the transaction builder, I tried to perform a Payment Operation by trying to transfer 2XLM to the 2nd account. However I recieved the following response :

{
  "type": "https://stellar.org/horizon-errors/transaction_failed",
  "title": "Transaction Failed",
  "status": 400,
  "detail": "The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details.  Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html",
  "extras": {
    "envelope_xdr": "AAAAAKNyr+6/r2REKzMV3sOL4jztg1HSdqlQhmthUU41BjPdAAAAZAAEmkQAAAADAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAmWhqbEZTUrZWFtvR1HU7VUW0pp3BwN4E9h4iQwvMr9kAAAAAAAAAAAExLQAAAAAAAAAAATUGM90AAABAHvtdpnjhq3usHFphQ/4naDHbKVhu+QqD8UFSavo/qlGo7Yiz/dLI3lQ0fmfa37uvwXWsYAn8mObDkrTjofc3Aw==",
    "result_codes": {
      "transaction": "tx_failed",
      "operations": [
        "op_no_destination"
      ]
    },
    "result_xdr": "AAAAAAAAAGT/////AAAAAQAAAAAAAAAB////+wAAAAA="
  }
}

So can someone tell me which operation I need to use to send XLM to an un-initialised address so I can activate it, not by using friendbot.

Paras
  • 3,191
  • 6
  • 41
  • 77

2 Answers2

1

First, you need to execute Create Account from the Transaction Builder. Only then you can transfer funds to this address.

igobivo
  • 433
  • 1
  • 4
  • 17
0

I think it's because the Stellar laboratory is not set up for this exact use case. It is more for getting a general feel of the basics. In order to create an account this way using an SDK and communicating with horizon you would have to both create the account and fund it in a single transaction, and therefore you would have to input the source account's secret key.

In the Stellar lab's account creation tab there is no way to input a source address its secret key (or at least I didn't see one).

So in your example, your first account is created and funded by the testbot. However, when you create the second account and try to send a payment to it from the first account, the reason it fails is because the second account is not yet a valid account as it has not been funded yet. Kind of a chicken and egg problem.

The good news is you can definitely do this using the SDK, but I haven't found a way to do it using the lab.

This from stellar.org about building transactions: https://www.stellar.org/developers/js-stellar-base/reference/building-transactions.html

TransactionBuilder The TransactionBuilder class is used to construct new transactions. TransactionBuilder is given an account that is used as transaction’s “source account”. The transaction will use the current sequence number of the given Account object as its sequence number and increments the given account’s sequence number when build() is called on the TransactionBuilder.

Operations can be added to the transaction calling addOperation(operation) for each operation you wish to add to the transaction. See operation.js for a list of possible operations you can add. addOperation(operation) returns the current TransactionBuilder object so you can chain multiple calls.

After adding the desired operations, call the build() method on the TransactionBuilder. This will return a fully constructed Transaction. The returned transaction will contain the sequence number of the source account. This transaction is unsigned. You must sign it before it will be accepted by the Stellar network.

# This is the relevant code

StellarSdk.Network.useTestNetwork();
// StellarBase.Network.usePublicNetwork(); if this transaction is for the public network
// Create an Account object from an address and sequence number.

var account=new StellarBase.Account("GD6WU64OEP5C4LRBH6NK3MHYIA2ADN6K6II6EXPNVUR3ERBXT4AN4ACD","2319149195853854");

var transaction = new StellarBase.TransactionBuilder(account, {
      fee: StellarBase.BASE_FEE
    })
        // add a payment operation to the transaction
        .addOperation(StellarBase.Operation.payment({
                destination: "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW",
                asset: StellarBase.Asset.native(),
                amount: "100.50"  // 100.50 XLM
            }))
        // add a set options operation to the transaction
        .addOperation(StellarBase.Operation.setOptions({
                signer: {
                    ed25519PublicKey: secondAccountAddress,
                    weight: 1
                }
            }))
        // mark this transaction as valid only for the next 30 seconds
        .setTimeout(30)
        .build();

# Note that it is adding different operations to a single transaction.