Example #1
0
        //I DO NOT RECOMMEND SENDING SECRET SEEDS OVER A NETWORK (ESPECIALLY UNENCRYPTED), THIS IS JUST AN EXAMPLE OF HOW YOU MIGHT FORM AN API USING THE SDK
        public async Task <IActionResult> SetInflationDestination([FromBody] SetInflationDestinationRequest request)
        {
            try
            {
                Network.UseTestNetwork();
                var source = KeyPair.FromAccountId(request.AccountId);
                var signer = KeyPair.FromSecretSeed(request.Seed);
                var inflationDestination = KeyPair.FromAccountId(request.InflationDestination);


                //For Livenet use https://horizon.stellar.org
                using (var server = new Server("https://horizon-testnet.stellar.org"))
                {
                    AccountResponse sourceAccount = await server.Accounts.Account(source);

                    var sequenceNumber = sourceAccount.SequenceNumber;
                    var account        = new Account(source, sequenceNumber);

                    var operation = new SetOptionsOperation.Builder()
                                    .SetInflationDestination(inflationDestination)
                                    .SetSourceAccount(source)
                                    .Build();

                    var memo = Memo.Text("Sample Memo");

                    Transaction transaction = new Transaction.Builder(account).AddOperation(operation).AddMemo(memo).Build();

                    var transactionXDR = transaction.ToUnsignedEnvelopeXdr();
                    transaction.Sign(signer);
                    var test = transaction.ToEnvelopeXdrBase64();

                    await server.SubmitTransaction(test);

                    return(Ok());
                }
            }
            catch (Exception Ex)
            {
                return(StatusCode(500, "Something went wrong"));
            }
        }