How to use the stellar-sdk.Server function in stellar-sdk

To help you get started, we’ve selected a few stellar-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github satoshipay / solar / src / components / Subscribers.tsx View on Github external
/**
 * This file contains reactive components that subscribe to data (like an account balance) and
 * re-render their contents whenever the data changes.
 *
 * These components do not render any UI by themselves. Wrap your representational components in
 * them to obtain some data and receive live updates.
 */

import React from "react"
import { Server, Transaction } from "stellar-sdk"
import { observer } from "mobx-react"
import { subscribeToAccount, subscribeToRecentTxs, AccountObservable } from "../lib/subscriptions"

// TODO: Should probably be stored in context
const horizonLivenet = new Server("https://stellar-horizon.satoshipay.io/")
const horizonTestnet = new Server("https://stellar-horizon-testnet.satoshipay.io/")

type HorizonRenderProp = (horizon: Server) => React.ReactElement

/**
 * @example
 * 
 *   {horizon => (
 *     <div>Currently used horizon server: {horizon.serverURL}</div>
 *   )}
 * 
 */
export const Horizon = (props: { children: HorizonRenderProp; testnet: boolean }) =&gt; {
  const horizon = props.testnet ? horizonTestnet : horizonLivenet
  return props.children(horizon)
}
github irisli / bookmaker / bookmaker.js View on Github external
const StellarSdk = require('stellar-sdk');
const keys = require('./keys');
const deleteAllOffers = require('./deleteAllOffers');
const createOffer = require('./createOffer');
const changeTrust = require('./changeTrust');
const simplePayment = require('./simplePayment');
var sleep = require('sleep');
const https = require('https');

const Server = new StellarSdk.Server(keys.horizon);

const baseBuying = new StellarSdk.Asset('XLM', null);
const counterSelling = new StellarSdk.Asset('USD', keys.issuer.accountId());
const OrderBookSetup = Server.orderbook(baseBuying, counterSelling);

async function main() {
  try {
    // http://www.investopedia.com/ask/answers/06/eurusd.asp
    //   "In a currency pair, the first currency in the pair is called the base
    //   currency and the second is called the quote currency.""
    // Using an example with a similarly "weak" currency, the Japanese Yen
    // Base/Counter
    // JPY/USD = 0.0085 (with a penny, you can buy a yen)
    // Base: JPY
    // Counter: USD
github stellar / dashboard / backend / ledgers.js View on Github external
(lastLedger) => {
        let pagingToken;
        if (!lastLedger) {
          pagingToken = "now";
        } else {
          pagingToken = lastLedger.paging_token;
        }

        var horizon = new stellarSdk.Server("https://horizon.stellar.org");
        horizon
          .ledgers()
          .cursor(pagingToken)
          .limit(200)
          .stream({
            onmessage: (ledger) => {
              let newLedger = _.pick(ledger, [
                "sequence",
                "closed_at",
                "paging_token",
                "operation_count",
              ]);
              newLedger["transaction_count"] =
                ledger.successful_transaction_count +
                ledger.failed_transaction_count;
              postgres.LedgerStats.create(newLedger).then(() => {
github stellar / dashboard / frontend / components / App.js View on Github external
.then(response => {
        let lastLedger = response.data._embedded.records[0];

        new Server(horizonURL).ledgers().cursor(lastLedger.paging_token)
          .stream({
            onmessage: ledger => this.emitter.emit(eventName, ledger)
          });
      });
  }
github orbitlens / stellar-notifier / logic / stellar-connector.js View on Github external
const {Server: HorizonServer} = require('stellar-sdk'),
    config = require('../models/config')

console.log(`Using Horizon server ${config.horizon}`)

module.exports = {
    /**
     * Horizon wrapper instance
     */
    horizon: new HorizonServer(config.horizon)//a Horizon wrapper instance
}
github satoshipay / solar / src / context / stellar.tsx View on Github external
setContextValue(prevValues => ({
          horizonLivenet:
            horizonLivenetURL !== String(prevValues.horizonLivenet.serverURL)
              ? new Server(horizonLivenetURL)
              : prevValues.horizonLivenet,
          horizonTestnet:
            horizonTestnetURL !== String(prevValues.horizonTestnet.serverURL)
              ? new Server(horizonTestnetURL)
              : prevValues.horizonTestnet
        }))
github satoshipay / solar / src / context / stellar.tsx View on Github external
const secondaryResponse = await fetch(secondaryHorizonURL)
  return secondaryResponse.ok ? secondaryHorizonURL : primaryHorizonURL
}

interface Props {
  children: React.ReactNode
}

interface ContextType {
  horizonLivenet: Server
  horizonTestnet: Server
}

const initialValues: ContextType = {
  horizonLivenet: new Server("https://stellar-horizon.satoshipay.io/"),
  horizonTestnet: new Server("https://stellar-horizon-testnet.satoshipay.io/")
}

const StellarContext = React.createContext(initialValues)

export function StellarProvider(props: Props) {
  const [contextValue, setContextValue] = React.useState(initialValues)

  React.useEffect(() =&gt; {
    let cancelled = false

    const init = async () =&gt; {
      const [horizonLivenetURL, horizonTestnetURL] = await Promise.all([
        checkHorizonOrFailover("https://stellar-horizon.satoshipay.io/", "https://horizon.stellar.org"),
        checkHorizonOrFailover("https://stellar-horizon-testnet.satoshipay.io/", "https://horizon-testnet.stellar.org")
      ])
github mobius-network / wallet / src / core / services / stellar / server.js View on Github external
import { Server, Network } from 'stellar-sdk';
import { stellarTestnet, stellarHorizonUrl } from 'utils/env';

if (stellarTestnet) {
  Network.useTestNetwork();
} else {
  Network.usePublicNetwork();
}

export const stellarServer = new Server(stellarHorizonUrl);

export const submitTransaction = (...args) => stellarServer.submitTransaction(...args);
github jackyzha0 / PacketBook / functions / messaging / __main__.js View on Github external
function sendStellar(senderPriv, receiverPub, amnt){
		StellarSdk.Network.useTestNetwork();
		var server = new StellarSdk.Server("https://horizon-testnet.stellar.org");
		var sourceKeys = StellarSdk.Keypair.fromSecret(senderPriv);
		var destinationId = receiverPub;
		var transaction;
	
		
		server.loadAccount(destinationId)
		  .catch(StellarSdk.NotFoundError, function (error) {
		    	send(from.number, "Nonexistant address" , to.number);
		    	throw error;
		  })
		  .then(function() {
		    return server.loadAccount(sourceKeys.publicKey());
		  })
		  .then(function(sourceAccount) {
		    transaction = new StellarSdk.TransactionBuilder(sourceAccount)
		      .addOperation(StellarSdk.Operation.payment({
github satoshipay / solar / stories / TransactionReviewDialog.tsx View on Github external
function SampleWebAuth(props: SampleWebAuthProps) {
  const horizon = new Server("https://horizon.stellar.org")
  const WebAuth = useWebAuth()

  const promise = React.useMemo(
    () =>
      (async () => {
        const account = await horizon.loadAccount(props.accountID)
        const webauthMetadata = await WebAuth.fetchWebAuthData(horizon, props.issuerID)

        const transaction = await WebAuth.fetchChallenge(
          webauthMetadata!.endpointURL,
          webauthMetadata!.signingKey,
          account.id
        )
        return transaction
      })(),
    []