UMI Framework
A Solana Framework for JavaScript clients
Umi is a modular framework for building and using JavaScript clients for Solana programs. It provides a zero-dependency library that defines a set of core interfaces that libraries can rely on without being tied to a specific implementation. It is then up to the end-user to choose the implementation that best suits their needs. Umi also provides a set of default implementations and bundles that can be used out of the box allowing developers to get started quickly.
Installation
For end-users
End-users using Umi to build applications need to install Umi and select the plugins they want to use. Alternatively, they can install the default bundle that includes a set of plugins that's suitable for most use cases. Note that, for now, the default bundle relies on web3.js for some of the interfaces so we have to install it as well.
Then, you can create a new Umi instance using the createUmi
function of the default bundle.
Then you want to tell Umi which wallet to use. This can either be a keypair or the solana wallet adapter.
That's it, now pass your Umi instance around and add more plugins as needed.
For library authors
Library authors that want to use Umi's interfaces to drastically reduce their dependencies only need to install the main Umi library. It is highly recommended to install it as a peer dependency to ensure the end-user does not end up with multiple versions of the Umi library.
You can then use Umi's Context
object or a subset of it to inject any interface you need in your functions. For instance:
For testing
Also note that Umi comes with a testing bundle that can help both end-users and library authors to test their code. For instance, it includes a MockStorage
implementation used for both the UploaderInterface
and the DownloaderInterface
so you can reliably test your code without having to rely on a real storage provider.
Connecting to an RPC
Connecting Umi to an RPC is as simple as creating an umi instance and passing through your rpc end point as the first argument. It is recommended to use at least a free RPC end point from one of the many Solana RPC providers and not use the public endpoint of https://api.mainnet-beta.solana.com
due to it's restrictions and limitations.
Connecting Umi to devnet is as simple as swapping out the RPC end point for that of a Devnet endpoint.
Registering Programs and Clients
Sometimes Umi may require you to register programs/clients directly to it. To do this you can call the .use()
method from your umi instance and pass in the client as the argument. In the below example we'll register the mpl-token-metdata
client to UMI.
You can chain .use()
together to register multiple clients.
Connecting w/ a Secret Key
To use Umi you'll need to register a wallet in order to send transactions. To use a file system wallet you can import the json stored private key and convert it to a keypair for use with Umi.
Connecting w/ Wallet Adapter
Umi can connect to solana-labs/wallet-adapter
directly to provide a seemless experiance for users on your front end. This prebuilt wallet UI is a great starting place for websites that are looking for user transactions and interactions. For this example we'll create a simple useUmi
hook in React.
From here on you can import your useUmi
hook into your components and use as needed.
Getting Started using the JavaScript
Metaplex provides a JavaScript library that can be used to interact with Core Assets. Thanks to the Umi framework, it ships without many opinionated dependencies thus providing a lightweight library that can be used in any JavaScript project.
To get started, you'll need to install the Umi framework and the Core JavaScript library.
Next, you should create your Umi
instance and install the mplCore
plugin like so.
Then instruct Umi which wallet to use. This can either be a keypair or the solana wallet adapter.
That's it, you can now interact with Core Assets and Core Collections by using the various functions provided by the library and passing your Umi
instance to them. Here's an example of creating an Asset:
Create Asset
JavaScript
To then fetch the data of your newly created asset you can use:
Fetch a single asset
JavaScript
Last updated