I am developing a React app, and I have code from two different applications I wrote:
Application A uses Metaplex to find all the NFTs owned by a user (wallet address):
import { Connection as MetaConnection } from "@metaplex/js/";
import { Metadata, MetadataData } from "@metaplex-foundation/mpl-token-metadata";
const lookupNfts = async () => {
let metaConnection = new MetaConnection('mainnet-beta');
const nftsmetadata = await Metadata.findDataByOwner(metaConnection, props.walletKey);
// Now I have a list of NFTs via metadata
}
"dependencies": {
"@metaplex-foundation/mpl-token-metadata": "^1.2.5",
"@metaplex/js": "^4.12.0",
"@solana/spl-token": "^0.1.8",
"@solana/web3.js": "^1.35.3",
}
Application B does a payment between wallets of an NFT:
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import { Account } from "@solana/spl-token"; // ERROR on this line, see screenshot
async function transfer_tokens(wallet: Keypair, connection: Connection, amount: number, reciver_token_account: Account, from_token_account: Account) {
// If tx takes more when 60 seconds to complete you will receive error here
const transfer_tx = await splToken.transfer(
connection,
wallet,
from_token_account.address,
reciver_token_account.address,
wallet,
amount,
[wallet],
false,
splToken.TOKEN_PROGRAM_ID,
)
However, when I try to use this code together in one application, it doesn’t work...
There seems to be a conflict. The dependency from application A pulls in @solana/spl-token@0.1.8
, but application B requires @solana/spl-token@0.2.0
.
If I upgrade solana/spl-token to 0.2.0, application A breaks. If I keep solana/spl-token at 0.1.8, application B doesn’t work.
I did a npm ls, and it shows this:
It seems the metaplex/js@4.12.0 has a dependency to 0.1.8, which is old.
How can I resolve this dependency conflict?