Instantiate a new instance of Asset class with the specified asset ID.
Optional
options: AssetOptionalInterfaceReturns a new Asset object with the asset id.
This method creates a new Asset controller instance that can be used to interact with an existing asset. It does not create a new asset in the database.
// Import the pre-initialized factory from your app's initialization file
import { Asset } from "utils/topiaInit.ts";
// Create an Asset instance with credentials
const assetInstance = await Asset.create(assetId, {
credentials: {
interactiveNonce,
interactivePublicKey,
assetId,
urlSlug,
visitorId
}
});
// Use the instance to interact with the asset
await assetInstance.fetchAssetById();
Upload a new Asset to the Topia platform and return a new instance of Asset class.
Returns a new Asset object with the asset details.
This method both creates a new asset in the database and returns an Asset controller instance. A valid API key with appropriate permissions is required.
// Import the pre-initialized factory from your app's initialization file
import { Asset } from "utils/topiaInit.ts";
// Prepare the asset payload
const assetPayload = {
assetName: "My Decorative Asset",
bottomLayerURL: "https://example.com/bottom-layer.png",
creatorTags: { "decorations": true },
tagJson: "[{"label":"decorations","value":"decorations"}]",
isPublic: true,
topLayerURL: "https://example.com/top-layer.png"
};
// Upload the asset using your API key
const asset = await Asset.upload(assetPayload, apiKey);
// Access the new asset's properties
console.log(asset.id);
Factory for creating Asset instances. Use this factory to create or upload assets in the Topia platform.
Remarks
This factory should be instantiated once per application and reused across your codebase.
Keywords
asset, factory, create, upload, instantiate, topia
Example