• GeneralSupport
  • Sending lumens into an account in a Standalone Stellar node

Hi,

I setup a standalone stellar network by changing the NETWORK_PASSPHRASE as mentioned here.
I got the root account key in the logs after starting the network. Let call that root ROOT_ACCOUNT_KEY. I could also validate that it was the root account key by connecting to my standalone network and getting its balance which is 100000000000. I went ahead to generate a random seed and use it's address to send some XLM inside. The code below illustrates that

public static void main(String[] args) throws IOException {
    SetupStellarServer setupServer = new SetupStellarServer(ROOT_ACCOUNT_KEY);
    try {
     	     setupServer.createAccount(RANDOM_ADDRESS, "", String.valueOf(1));
	     setupServer.sendFunds(RANDOM_ADDRESS, String.valueOf(1000), "");
	     logger.info("Send....");
    }catch(ErrorResponse e) {
	     logger.error(e.getBody());
    }
}    

public SetupStellarServer(String seed){
	     Network network = new Network(PRIVATE_NETWORK_PASSPHRASE);
	     Network.use(network);
	     if(seed!=null){
     		keyPair = KeyPair.fromSecretSeed(seed);
	     }else{
		     keyPair=KeyPair.random();
	     }
     if(stellarServer == null)
             stellarServer = new Server(URL);
}

public AccountResponse createAccount(String destinationAccountId, String payload, String amount) throws IOException{
     KeyPair destination = KeyPair.fromAccountId(destinationAccountId);
     AccountResponse destinationAccount=null;
     Network network = new Network(PRIVATE_NETWORK_PASSPHRASE);
     Network.use(network);
     Operation operation=null;
     try{
	     destinationAccount=stellarServer.accounts().account(destination);
     }catch(ErrorResponse e){
	     if(e.getBody().toUpperCase().contains("NOT FOUND")){
		     logger.info("Account does not exist yet. We will now create it with 1 XLM:"+destinationAccountId);
	     }else{
		     throw e;
	     }
     }
     if(destinationAccount==null){
	     operation = new CreateAccountOperation.Builder(KeyPair.fromAccountId(destinationAccountId), amount).setSourceAccount(keyPair).build();
	     logger.info("Account creator is:"+keyPair.getAccountId());
	     AccountResponse sourceAccount= stellarServer.accounts().account(keyPair);
	     Transaction transaction = new Transaction.Builder(sourceAccount)
				.addOperation(operation)
		        .addMemo(Memo.text(payload))
		        .build();
	     transaction.sign(keyPair);
	     stellarServer.submitTransaction(transaction);
     }
     return  destinationAccount;
}


public  SubmitTransactionResponse sendFunds( String destinationAccountId, String amount, String payload) throws IOException{
     KeyPair destination = KeyPair.fromAccountId(destinationAccountId);
     Network network = new Network(PRIVATE_NETWORK_PASSPHRASE);
     Network.use(network);
     Asset asset= new AssetTypeNative();
     stellarServer.accounts().account(destination);
     Operation operation=new PaymentOperation.Builder(destination, asset, amount).build();
     AccountResponse sourceAccount= stellarServer.accounts().account(keyPair);
     Transaction transaction = new Transaction.Builder(sourceAccount)
			.addOperation(operation)
	        .addMemo(Memo.text(payload))
	        .build();
     transaction.sign(keyPair);
     return  stellarServer.submitTransaction(transaction);
}

I'm using the java SDK for stellar. This code works well on the testnet but when I run it on the standalone network, I keep getting

{
    "type": "https://stellar.org/horizon-errors/not_found",
    "title": "Resource Missing",
    "status": 404,
    "detail": "The resource at the url requested was not found.  This is usually occurs for one of two reasons:  The url requested is not valid, or no data in our database could be found with the parameters provided."
}

I understand the exception might be because the account does not existing but AFAIK, to create an account on the stellar network, you need to do a transfer towards the account's address. This is what I doing in the createAccount method. Also the URL exists and is reachable. I could validate that by getting the balance of the root account key programmatically.

I have been working on this for the pass 3 days. I'm frustrated. I believe that I'm missing something.

Any clue will be welcoming.
Thanks.

The 404 response suggests it is posting to the right server, but hitting the wrong endpoint. I would debug the call to stellarServer.submitTransaction(transaction) to make sure it constructs the correct endpoint. If not, you might need to adjust the value URL.

    Jem Thanks for replying.
    You are right it looks like the endpoint http://myhorizon.stellar.url/transactions is unreachable. After debugging, I found the following with doing stellarServer.submitTransaction(transaction)

     {
        "type": "https://stellar.org/horizon-errors/timeout",
        "title": "Timeout",
        "status": 504,
        "detail": "Your request timed out before completing.  Please try your request again."
     }

    I confused because the http://myhorizon.stellar.url/accounts is reachable but not http://myhorizon.stellar.url/transactions.

    Do you have any clue?