SoLibrary
  • Solana
  • The Meme Coin Problem and Solution
  • Developing on Solana
  • From Rust To Deployment
  • Solana Blockchain Explorer
  • Building a Solana dAPP
  • Deploying a Solana dApp
  • Deploying a Solana Memecoin using CLI
  • Solana Smart Contracts
  • Send Solana via javascript functions
  • Candy Machine
  • Pump fun APIs
  • Metaplex
  • Metaplex Program Library
  • Solana Program Library
  • UMI Framework
  • Umi and Web3js Differences
  • Fetching Accounts
  • UMI Helpers
  • HTTP Requests
  • Umi's Interfaces
  • Interface implementations
  • Kinobi
  • UMI Plugins
  • Registering Programs
  • Public keys and Signers
  • Connecting RPCS
  • Serializer
  • Storage
  • Transactions
  • Web 3.JS Adapters
  • Metaplex Umi Plugins
  • Core JS SDK v1.0
  • Local Validator
  • SolScriptions
  • FAQ
  • Initialize
  • Write Inscription Data
  • Fetch
  • Clear
  • Close
  • Authority
  • Sharding
  • Getting Started using JavaScript
  • Getting started using the Inscriptions CLI
  • Core Candy Machine
  • Getting Started using JavaScript
  • Candy Guard
  • Assets
  • Creating a Core Candy Machine
  • Inserting Items
  • Updating The Core Candy Machine
  • Guard Groups
  • Special Guard Instructions
  • Fetching a Core Candy Machine
  • Minting
  • Withdrawing a Core Candy Machine
  • Address Gate Guard
  • Allocation
  • Allowlist Guard
  • Asset Burn Guard
  • Asset Burn Multi
  • Asset Payment Guard
  • Asset Payment Multi
  • Asset Mint Limit
  • Bot Tax Guard
  • End Date Guard
  • Edition
  • Freeze Sol Payment guard
  • Freeze Token Payment Guard
  • Gatekeeper Guard
  • Mint Limit Guard
  • NFT Burn Guard
  • NFT Gate Guard
  • NFT Mint Limit Guard
  • NFT Payment Guard
  • Program Gate Guard
  • Redeemed Amount Guard
  • Sol Fixed Fee Guard
  • Sol Payment Guard
  • Start Date Guard
  • Third Party Signer Guard
  • Token Burn Guard
  • Token Gate Guard
  • Token Payment Guard
  • Token2022 Payment Guard
  • Generating Custom Guard Client for Core Candy Machine
Powered by GitBook
On this page

Web 3.JS Adapters

The @solana/web3.js library is currently widely used in the Solana ecosystem and defines its own types for public keys, transactions, instructions, etc.

PreviousTransactionsNextMetaplex Umi Plugins

Last updated 10 months ago

When creating Umi, we wanted to move away from the class-based types defined in @solana/web3.js and instead use a more functional approach by relying only on TypeScript types. This unfortunately means that not all types from @solana/web3.js are compatible with the ones provided by Umi and vice versa.

To help with this issue, Umi provides a set of adapters that allows us to parse types to and from their Web3.js counterparts.

To use them, you will first need to install the package.

npm install @metaplex-foundation/umi-web3js-adapters

Then, you will have access to a bunch of helper methods to convert to and from Web3.js types.

// For public keys.
fromWeb3JsPublicKey(myWeb3JsPublicKey)
toWeb3JsPublicKey(myUmiPublicKey)

// For keypairs.
fromWeb3JsKeypair(myWeb3JsKeypair)
toWeb3JsKeypair(myUmiKeypair)

// For transactions.
fromWeb3JsTransaction(myWeb3JsTransaction)
toWeb3JsTransaction(myUmiTransaction)
fromWeb3JsLegacyTransaction(myLegacyWeb3JsTransaction)
toWeb3JsLegacyTransaction(myUmiTransaction)

// For transaction messages.
fromWeb3JsMessage(myWeb3JsTransactionMessage)
toWeb3JsMessage(myUmiTransactionMessage)
toWeb3JsMessageFromInput(myUmiTransactionInput)

// For instructions.
fromWeb3JsInstruction(myWeb3JsInstruction)
toWeb3JsInstruction(myUmiInstruction)

Let's take a look at an example. Say you want to issue a vanilla token using the @identity.com/solana-gateway-ts library which relies on @solana/web3.js. It offers an issueVanilla function that creates an instruction but this isn't compatible with Umi.

To go around this, you could create a wrapper function that converts the issueVanilla function into a Umi-compatible one. Precisely, this means we need to convert the returned instruction using fromWeb3JsInstruction and convert any public key passed into the function using toWeb3JsPublicKey.

import { issueVanilla as baseIssueVanilla } from '@identity.com/solana-gateway-ts'
import {
  fromWeb3JsInstruction,
  toWeb3JsPublicKey,
} from '@metaplex-foundation/umi-web3js-adapters'

export const issueVanilla = (
  gatewayTokenAccount: PublicKey,
  payer: Signer,
  gatekeeperAccount: PublicKey,
  owner: PublicKey,
  gatekeeperAuthority: Signer,
  gatekeeperNetwork: PublicKey
) =>
  transactionBuilder([
    {
      instruction: fromWeb3JsInstruction(
        baseIssueVanilla(
          toWeb3JsPublicKey(gatewayTokenAccount),
          toWeb3JsPublicKey(payer.publicKey),
          toWeb3JsPublicKey(gatekeeperAccount),
          toWeb3JsPublicKey(owner),
          toWeb3JsPublicKey(gatekeeperAuthority.publicKey),
          toWeb3JsPublicKey(gatekeeperNetwork)
        )
      ),
      signers: [payer, gatekeeperAuthority],
      bytesCreatedOnChain: 0,
    },
  ])

@metaplex-foundation/umi-web3js-adapters