Features
Umi's Interfaces
The core interfaces
Umi defines a set of core interfaces that makes it easy to interact with the Solana blockchain. Namely, they are:
Signer: An interface representing a wallet that can sign transactions and messages.EddsaInterface: An interface to create keypairs, find PDAs and sign/verify messages using the EdDSA algorithm.RpcInterface: An interface representing a Solana RPC client.TransactionFactoryInterface: An interface allowing us to create and serialize transactions.UploaderInterface: An interface allowing us to upload files and get a URI to access them.DownloaderInterface: An interface allowing us to download files from a given URI.HttpInterface: An interface allowing us to send HTTP requests.ProgramRepositoryInterface: An interface for registering and retrieving programs.
The Context interface
The interfaces above are all defined in a Context interface that can be used to inject them in your code. The Context type is defined as follows:
interface Context {
downloader: DownloaderInterface;
eddsa: EddsaInterface;
http: HttpInterface;
identity: Signer;
payer: Signer;
programs: ProgramRepositoryInterface;
rpc: RpcInterface;
transactions: TransactionFactoryInterface;
uploader: UploaderInterface;
};
As you can see the Signer interface is used twice in the context:
- Once for the
identitywhich is the signer using your app. - Once for the
payerwhich is the signer paying for things like transaction fees and storage fees. Usually this will be the same signer as theidentitybut separating them offers more flexibility for apps – e.g. in case they wish to abstract some costs from their users to improve the user experience.
The Umi interface
The Umi interface is built on top of this Context interface and simply adds a use method which enables end-users to register plugins. It is defined as follows:
interface Umi extends Context {
use(plugin: UmiPlugin): Umi;
}
Therefore, end-users can add plugins to their Umi instance like so:
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { walletAdapterIdentity } from '@metaplex-foundation/umi-signer-wallet-adapters';
import { awsUploader } from '@metaplex-foundation/umi-uploader-aws';
import { myProgramRepository } from '../plugins';
const umi = createUmi('https://api.mainnet-beta.solana.com')
.use(walletAdapterIdentity(...))
.use(awsUploader(...))
.use(myProgramRepository());