import { AstralSDK } from '@decentralized-geo/astral-sdk';import { ethers } from 'ethers';// Create a provider and signerconst provider = new ethers.JsonRpcProvider('https://sepolia.base.org');const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);// Initialize the SDKconst astral = new AstralSDK({ chainId: 84532, // Base Sepolia signer: wallet, apiUrl: 'https://api.astral.global'});// Now you can use both location and compute modulesconst attestation = await astral.location.offchain.create({ ... });const distance = await astral.compute.distance(uid1, uid2, options);
import { AstralSDK } from '@decentralized-geo/astral-sdk';import { ethers } from 'ethers';// Connect to browser wallet (MetaMask, etc.)const provider = new ethers.BrowserProvider(window.ethereum);const signer = await provider.getSigner();// Get the chain ID from the connected walletconst network = await provider.getNetwork();// Initialize the SDKconst astral = new AstralSDK({ chainId: Number(network.chainId), signer: signer, apiUrl: 'https://api.astral.global'});
import { AstralSDK } from '@decentralized-geo/astral-sdk';import { ethers } from 'ethers';// Provider-only (no signer)const provider = new ethers.JsonRpcProvider('https://sepolia.base.org');const astral = new AstralSDK({ chainId: 84532, provider: provider, apiUrl: 'https://api.astral.global'});// Can verify attestationsconst result = await astral.location.onchain.verify(attestation);// Can compute (API calls don't require signer)const distance = await astral.compute.distance(uid1, uid2, options);// Cannot submit to EAS without signer// await astral.compute.submit(attestation); // Would throw error
interface AstralConfig { /** * Target chain ID. Required. * All operations are scoped to this chain. */ chainId: number; /** * Ethers signer for signing attestations and transactions. * Required for creating attestations and submitting to EAS. */ signer?: Signer; /** * Ethers provider for read-only blockchain operations. * If not provided and signer is present, uses signer's provider. */ provider?: Provider; /** * Astral API base URL. * Defaults to 'https://api.astral.global' */ apiUrl?: string; /** * Enable debug logging. * Defaults to false. */ debug?: boolean; /** * Pre-register custom EAS schemas. * Useful for performance when using multiple schemas. */ schemas?: RuntimeSchemaConfig[]; /** * Default schema to use when none is specified. * If not provided, uses the built-in location schema. */ defaultSchema?: RuntimeSchemaConfig; /** * Throw errors on schema validation failures. * Defaults to false (logs warnings instead). */ strictSchemaValidation?: boolean;}
You can also import submodules directly for tree-shaking:
Copy
// Import just what you needimport { LocationModule } from '@decentralized-geo/astral-sdk/location';import { ComputeModule } from '@decentralized-geo/astral-sdk/compute';// Use independentlyconst location = new LocationModule({ chainId: 84532, signer: wallet });const compute = new ComputeModule({ apiUrl: 'https://api.astral.global', chainId: 84532 });