Installation
Library Setup
- Custom Hook
- Direct Usage
hooks/useParaStellar.ts
Install and configure the Stellar SDK for use with Para SDK in React Native
npm install @getpara/stellar-sdk-v14-integration @stellar/stellar-sdk --save-exact
import { useMemo } from 'react';
import { useClient, useAccount } from '@getpara/react-native-wallet';
import { createParaStellarSigner } from '@getpara/stellar-sdk-v14-integration';
import { Horizon, Networks } from '@stellar/stellar-sdk';
const HORIZON_URL = "https://horizon.stellar.org";
export function useParaStellar() {
const para = useClient();
const { isConnected } = useAccount();
const signer = useMemo(() => {
if (!para || !isConnected) return null;
return createParaStellarSigner({
para,
networkPassphrase: Networks.PUBLIC,
});
}, [para, isConnected]);
const server = new Horizon.Server(HORIZON_URL);
return { server, signer, isLoading: !para };
}
import { createParaStellarSigner } from "@getpara/stellar-sdk-v14-integration";
import { Horizon, Networks } from "@stellar/stellar-sdk";
import { para } from "./para";
const server = new Horizon.Server("https://horizon.stellar.org");
const signer = createParaStellarSigner({
para,
networkPassphrase: Networks.PUBLIC,
});
console.log("Stellar address:", signer.address);
Networks.PUBLIC with Networks.TESTNET and use the testnet Horizon URL: https://horizon-testnet.stellar.org. You can fund testnet accounts using Stellar’s Friendbot.