I want to check if a wallet contain an NFT by its address, but when I try to import keypair module I get an error that it does not exist.

Cannot find reference 'keypair' in 'init.py'

import os
import json
from solana.rpc.api import Client
from solana.keypair import Keypair
from nft_addresses import nft_addresses

# Set up Solana RPC endpoint
rpc_endpoint = 'https://api.mainnet-beta.solana.com'
client = Client(rpc_endpoint)

# Set up Solana wallet keypair
wallet_keypair = Keypair.from_secret_key(bytes.fromhex(os.environ.get('WALLET_SECRET_KEY')))

# Define Discord bot command
async def check_nft(ctx):
    # Get user's Solana wallet address
    user_address = 'user-address-here'

    # Check if user holds one of the NFTs
    for nft_address in nft_addresses:
        token_account_info = await client.get_account_info(nft_address)
        token_data = json.loads(token_account_info['data'][0])
        for account in token_data['accountList']:
            if account['account'] == user_address and account['amount'] > 0:
                await ctx.send('You hold one of the NFTs in our collection!')

    await ctx.send('Sorry, you do not hold any NFTs in our collection.')

# Add Discord bot command to client
client.add_command('check_nft', check_nft)

# Connect bot to Discord server

Is the keypair module deprecated?

2 Answers 2


you must use from solders.keypair import Keypair. This was deprecated in the latest solana-py update. This happened with a lot of features. https://github.com/michaelhly/solana-py/blob/master/CHANGELOG.md


For those who come later, the answer has changed since @pixeled replied. The module has been refactored to use a new module called solders, written in Rust.

The new import is:

from solders.keypair import Keypair

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.