Introduction
Umi and Web3js Differences
Differences
When using Umi you may come across some differences between Umi and solana web3js.
Although having the same or similar import names these function differently and are not compatible between the two librarys out the box.
PublicKeys
Umi PublicKey
import { publicKey } from '@metaplex-foundation/umi'
const publicKey = publicKey('tst24HZ6pbcnraCv4r8acexfgXvyQwMSRgZRCg9gEX1')
Solana Web3js PublicKey
import { PublicKey } from '@solana/web3js'
const publicKey = new PublicKey('tst24HZ6pbcnraCv4r8acexfgXvyQwMSRgZRCg9gEX1')
These are just basic examples. To learn more about Umi's keypairs check out PublicKeys and Signers. There are also converters between both Umi and web3js Web3Js Adapters
Keypairs
Umi Keypair
const umi = createUmi(...)
const keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(secretKey))
Web3js Keypair
import { Keypair } from '@solana/web3js'
const publicKey = Keypair.fromSecretKey(new Uint8Array(JSON.parse(Wallet.DEV1)))
These are just basic examples. To learn more about Umi's keypairs check out PublicKeys and Signers. There are also converters between both Umi and web3js keypair types Web3Js Adapters
Transactions
Umi Transaction
const blockhash = await umi.rpc.getLatestBlockhash()
const transaction = const tx = umi.transactions.create({
version: 0,
payer: umi.identity.publicKey,
instructions: ix,
blockhash: blockhash.blockhash,
});
await umi.rpc.sendTransaction(tx)
Web3js Transaction
const wallet = useWallet()
const messageV0 = new TransactionMessage({
payerKey: SIGNER_WALLET.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: txInstructions,
}).compileToV0Message()
const tx = new VersionedTransaction(messageV0)
// send via useWallet hook
await wallet.sendTransaction(tx)
//or send via connection
await connection.sendTransaction(tx)
These are just basic examples. To learn more about Umi's Transiactions check out Transactions. There are also converters between both Umi and web3js Transaction types Web3Js Adapters