A JavaScript/TypeScript SDK for licensing user-generated content. Streamlines digital asset licensing with smart license templates, automated agreement creation, and seamless royalty management.
The SDK supports API key authentication for backend services and server-side applications. When an API key is provided, it will be automatically included in all HTTP requests to v1 API endpoints.
The SDK provides product management functionality to create products from signed agreement assets:
Copy
Ask AI
import { SpaceportSDK } from "@spaceport/sdk";async function productManagementExamples() { // Initialize SDK with a wallet and API key const sdk = SpaceportSDK.createWithAccount(account, { chain: "devnet", apiKey: process.env.SDK_API_KEY, }); // Get current user const currentUser = await sdk.users.getCurrentUser(); // Generate delegated attestation signatures for product creation const delegatedAttestationParams = await sdk.products.generateDelegatedAttestationSignatures(2); // For 2 products // Create products from agreement assets const productResult = await sdk.products.create({ robloxAssetId: "123456789", // Roblox asset ID agreementId: "e5a654c3-a5c9-4651-9c93-d0e947154a1a", // Agreement ID from your database productDetails: [ { assetId: "asset-uuid-1", // Asset ID from the agreement title: "My Awesome Product", description: "A product created from a signed agreement", }, { assetId: "asset-uuid-2", // Another asset ID from the agreement title: "Another Great Product", description: "Second product from the same agreement", }, ], delegatedAttestationParams, // Signatures generated above }); console.log("Product creation result:", productResult); if (productResult.success) { console.log("🎉 Products created successfully!"); }}
The SDK provides a query module for accessing licensing information and agreement history. The query module automatically connects to the appropriate data source based on your network configuration:
Copy
Ask AI
import { SpaceportSDK, SpaceportChainType, QueryClient } from "@spaceport/sdk";async function queryExamples() { // Option 1: Access the query module via the SDK instance // This automatically uses the environment from the SDK configuration const sdk = SpaceportSDK.create({ chain: "devnet" }); console.log(`Using environment: ${sdk.query.getEnvironment()}`); // 'devnet' // Query active listings const activeListings = await sdk.query.listings.getActiveListings({ first: 10, }); console.log(`Found ${activeListings.totalCount} active listings`); // Option 2: Use the QueryClient directly with a specific environment // This is useful for standalone queries or when you need to query multiple environments const queryClient = new QueryClient("testnet"); const testnetListings = await queryClient.listings.getActiveListings({ first: 5, }); // Common query examples // Get listings by licensor const licensorAddress = "0x1234..."; const licensorListings = await sdk.query.listings.getListingsByLicensor( licensorAddress ); // Get agreements for a licensee const licenseeAddress = "0xabcd..."; const licenseeAgreements = await sdk.query.agreements.getAgreementsByLicensee( licenseeAddress ); // Get agreements for a licensor const licensorAgreements = await sdk.query.agreements.getAgreementsByLicensor( licensorAddress ); // Get a specific listing by ID const listingId = "0x1234..."; // Listing identifier const listing = await sdk.query.listings.getListingById(listingId); // Get active agreements const activeAgreements = await sdk.query.agreements.getBindingAgreements(); // Get smart licenses const smartLicenses = await sdk.query.smartLicenses.getSmartLicenses({ first: 5, }); // Get a specific smart license by its hash const smartLicenseHash = "0xabcd..."; const smartLicense = await sdk.query.smartLicenses.getSmartLicenseByHash( smartLicenseHash ); // Execute custom queries using the underlying GraphQL client const client = sdk.query.getGraphQLClient(); const customQuery = ` query { listingObjects(where: { price_gt: "1000000000000000000" }) { id price licensor nftId } } `; const result = await client.query(customQuery).toPromise();}
The SDK provides user management functionality to create and retrieve users associated with wallet addresses:
Copy
Ask AI
import { SpaceportSDK } from "@spaceport/sdk";async function userManagementExamples() { // Initialize SDK with a wallet const account = privateKeyToAccount(`0x${process.env.YOUR_PRIVATE_KEY}`); const sdk = SpaceportSDK.createWithAccount(account, { chain: "devnet", apiKey: process.env.SDK_API_KEY, }); // Create a new user (wallet address is automatically included from SDK) const newUser = await sdk.users.create({ email: "[email protected]", firstName: "John", lastName: "Doe", }); console.log(`User created: ${newUser.userId}`); // Get the current user (based on the wallet address used to initialize the SDK) try { const currentUser = await sdk.users.getCurrentUser(); console.log( `Current user: ${currentUser.email} (${currentUser.walletAddress})` ); } catch (error) { console.log("No user found for current wallet address"); } // Get a user by specific wallet address const walletAddress = "0x1234567890123456789012345678901234567890"; try { const user = await sdk.users.getByWalletAddress(walletAddress); console.log(`User found: ${user.email}`); console.log(`Organization ID: ${user.organizationId}`); console.log(`Core login enabled: ${user.allowCoreLogin}`); } catch (error) { console.log(`No user found with wallet address: ${walletAddress}`); }}
resources/agreements.AgreementClientThe AgreementClient provides methods for interacting with licensing agreements on the Spaceport platform.
Agreements represent the legally binding contract formed when a licensee accepts a licensor’s listing terms.
This client handles actions like creating (signing), and accepting agreements, as well as querying agreement data.
resources/assets.AssetClientThe AssetClient is used to manage digital assets within the Spaceport ecosystem.
Assets are the core digital items, such as 3D models, audio files, or other creative works,
that can be licensed and monetized. This client handles creating and managing the metadata
and files associated with these assets.
resources/bondToken.BondTokenClientThe BondTokenClient provides an interface for interacting with the platform’s utility token, the Bond Token.
This token is used for payments, staking, and other economic activities within the Spaceport and Cultura ecosystem.
This client simplifies operations like checking balances, approving transfers, and minting new tokens.
resources/invoices.InvoiceClientThe InvoiceClient handles operations related to invoices, which are records of sales or usage of licensed assets.
Invoices are typically imported from external platforms (e.g., Roblox sales data) and are used as the basis
for calculating and distributing royalties to rights holders. This client can import, fetch, and even generate
mock invoice data for testing.
resources/listings.ListingClientThe ListingClient is used to manage listings on the Spaceport marketplace.
A listing is an offer made by a licensor to license one or more assets under specific terms,
such as price, duration, and royalties. This client handles creating and querying these listings.
resources/products.ProductClientThe ProductClient manages the lifecycle of products, which represent the instantiation of a licensed asset
on an external platform (e.g., a specific t-shirt on Roblox created from a licensed design).
Products link the Spaceport asset and agreement to its real-world counterpart,
enabling tracking and royalty calculations.
resources/royalties.RoyaltyClientThe RoyaltyClient handles the complex process of royalty management.
Royalties are the payments due to licensors based on the revenue generated by licensed products.
This client provides methods to register sales data (via invoices), calculate royalties,
and manage their payment and acceptance both on-chain and off-chain.
resources/smartLicenses.SmartLicenseClientThe SmartLicenseClient is used to manage Smart License templates on the blockchain.
A Smart License is a reusable, on-chain template that defines the terms and conditions of a license,
such as required licensee information or specific usage rights. These templates are then attached to listings
to standardize and automate the licensing process.
resources/users.UserClientThe UserClient manages user profiles within the Spaceport ecosystem.
A user account is typically associated with a wallet address and holds information
about the user’s identity and activities on the platform. This client handles
user creation and retrieval.