pythonblockchainsolana

I would like to get all transactions given an address


Given a Solana wallet address I would like to verify every single transaction ever confirmed to check other information, such as the receiver (or sender) and the amount sent (or received). So, as usual, I searched for some APIs. I found the following:

  1. Solana py
  2. PySolana

After that, I went to look which methods they offer. The one that seems to be close to what I wish is solana_client.get_confirmed_signature_for_address2 (available in 1), however my results do not match what its documentation shows. Here it is:

from solana.rpc.api import Client
solana_client = Client("https://api.devnet.solana.com")

solana_client.get_signatures_for_address("2AQdpHJ2JpcEgPiATUXjQxA8QmafFegfQwSLWSprPicm", limit=1)

I get this:

{'jsonrpc': '2.0', 'result': [], 'id': 1}

However, I should get its last signature, which seems to be this:

4SNQ4h1vL9GkmSnojQsf8SZyFvQsaq62RCgops2UXFYag1Jc4MoWrjTg2ELwMqM1tQbn9qUcNc4tqX19EGHBqC5u

Anyways, we can use SolanaBeach and check. Further, if we code as the documentation explains:

from solana.rpc.api import Client
solana_client = Client("https://api.devnet.solana.com")

solana_client.get_signatures_for_address("Vote111111111111111111111111111111111111111", limit=1)

I get this:

{'jsonrpc': '2.0', 'result': [{'blockTime': 1637328065, 'confirmationStatus': 'finalized', 'err': {'InstructionError': [0, {'Custom': 0}]}, 'memo': None, 'signature': '5yaeqDRCHWCGQMqNWhq3g6zqw63MBkri9i86hjK954YFFvnG2VCQJfszXsozDVUJbePagJieAzwsSY5H7Xd1jJhC', 'slot': 95301596}], 'id': 1}

Weird thing is "Vote111...11" seems not to be an address. Nevertheless, I get expected results, that is a signature, even though such signature can't be found by Solana Explorer...

Please, tell me what to fix. I have no idea what to do. I even tried to check if all Solana Explorers have their own API, but they do not. Probably because Solana already shares it, right?

EDIT

Well, it seems I need to enter the "account address as base-58 encoded string", thus the address becomes: HLiBGYYxaQqQx8UTPHEahqcd7aZjkDgN3bihc3hYM3SDUBGU9LFrQSnx9eje.

I also did that and I get:

{'jsonrpc': '2.0', 'error': {'code': -32602, 'message': 'Invalid param: WrongSize'}, 'id': 1}

Solution

  • Problem is not module nor function but endpoint.

    In Solana Doc I found endpoint for mainnet:

    https://api.mainnet-beta.solana.com
    
    https://solana-api.projectserum.com
    

    and it gives all values.


    On other page you can see that

    #Devnet#
    
    - Devnet serves as a playground for anyone who wants to take Solana for a test drive, as a user, token holder, app developer, or validator.
    - Application developers should target Devnet.
    - Potential validators should first target Devnet.
    - Key differences between Devnet and Mainnet Beta:
        - Devnet tokens are not real
        - Devnet includes a token faucet for airdrops for application testing
        - Devnet may be subject to ledger resets
        - Devnet typically runs a newer software version than Mainnet Beta
    
    #Testnet#
    
    -Testnet is where we stress test recent release features on a live cluster, particularly focused on network performance, stability and validator behavior.
    - Testnet tokens are not real
    - Testnet may be subject to ledger resets.
    - Testnet includes a token faucet for airdrops for application testing
    - Testnet typically runs a newer software release than both Devnet and Mainnet Beta
    

    Minimal working example for tests:

    from solana.rpc.api import Client
    
    all_addresses = [
        '2AQdpHJ2JpcEgPiATUXjQxA8QmafFegfQwSLWSprPicm',
        'Vote111111111111111111111111111111111111111',
        'fake address',
    ]
    
    #endpoint = 'https://api.devnet.solana.com'    # probably for `developing`
    #endpoint = 'https://api.testnet.solana.com'   # probably for `testing`
    endpoint = 'https://api.mainnet-beta.solana.com'
    #endpoint = 'https://solana-api.projectserum.com'
    
    solana_client = Client(endpoint)
    
    for address in all_addresses:
        print('address:', address)
        
        #result = solana_client.get_confirmed_signature_for_address2(address, limit=1)
        result = solana_client.get_signatures_for_address(address)#, before='89Tv9s2uMGaoxB8ZF1LV9nGa72GQ9RbkeyCDvfPviWesZ6ajZBFeHsTPfgwjGEnH7mpZa7jQBXAqjAfMrPirHt2')
        
        if 'result' in result:
            print('len:', len(result['result']))
    
            # I use `[:5]` to display only first 5 values
            for number, item in enumerate(result['result'][:5], 1):
                print(number, 'signature:', item['signature'])
    
            # check if there is `4SNQ4h1vL9GkmSnojQsf8SZyFvQsaq62RCgops2UXFYag1Jc4MoWrjTg2ELwMqM1tQbn9qUcNc4tqX19EGHBqC5u`
            for number, item in enumerate(result['result'], 1):
                if item['signature'].startswith('4SN'):
                    print('found at', number, '>>>', item['signature'])
    
        else:
            # error message 
            print(result)
    
        print('---')
    
        #solana_client.get_account_info(address)
    

    Result:

    address: 2AQdpHJ2JpcEgPiATUXjQxA8QmafFegfQwSLWSprPicm
    len: 1000
    1 signature: 89Tv9s2uMGaoxB8ZF1LV9nGa72GQ9RbkeyCDvfPviWesZ6ajZBFeHsTPfgwjGEnH7mpZa7jQBXAqjAfMrPirHt2
    2 signature: 3Ku2rDnAVo5Mj3r9CVSGHJjvn4H9rxzDvc5Cg5uyeCC9oa6p7enAG88pSfRfxcqhBh2JiWSo7ZFEAD3mP8teS1Yg
    3 signature: 3wiYCmfXb9n6pT3mgBag7jx6jBjeKZowkYmeakMibw4GtERFyyitrmmoPU6t28HpJJgWkArymWEGWQj8eiojswoD
    4 signature: 5vjV1wKU3ZEgyzqXCKrJcJx5jGC8LPqRiJBwhPcu62HQU64mkrvkK8LKYaTzX4x4p26UXSufWM57zKSxRrMgjWn3
    5 signature: 3aLk4xZPcWRogtvsFe8geYC177PK8s47mgqUErteRc9NJ4EF2iHi3GPsaj5guTwyiabhwivFhrrEk4YQgiE2hZs8
    found at 970 >>> 4SNQ4h1vL9GkmSnojQsf8SZyFvQsaq62RCgops2UXFYag1Jc4MoWrjTg2ELwMqM1tQbn9qUcNc4tqX19EGHBqC5u
    ---
    address: Vote111111111111111111111111111111111111111
    len: 1000
    1 signature: 67RRbUWGCrwmJ3hhLL7aB2K8gc6MewxwgAdfG7FeXQBaSstacqvuo9QUPZ6nhqXjJwYpKHihNJwFfcaAZHuyFmMc
    2 signature: 67PsyRRw8bXgtsB49htxcW2FE9cyyBrocUKacnrxJpqaBpFT6QDLrCkyovWnM8XyGKxTv3kqzmW72SH7gj3N8YJr
    3 signature: 675FWqrAjE5Bt6rf3KD2H2PCKUmEtrcD8BRRypdS7m2V22zXhrGn3SktP6JYW4ws6xEqDj52MZMH8RwNjoqgW4mt
    4 signature: 671K7N9FwaMAyBC4MEYbYb1ACYAendBbRMqKPvr3h63dt5ybAPHyppjHwxq1yPDjqaRUwCBVU9o5dVqgsdVabint
    5 signature: 666jBXXLwmB5tuvufhNn8Q7A3eCzGo6CBFD5BYJkuGfBf1bRoAGz4DeEpUAKsUrRk4NdRBhYkwfrhyZjgFmo3Dp2
    ---
    address: fake address
    {'jsonrpc': '2.0', 'error': {'code': -32602, 'message': 'Invalid param: Invalid'}, 'id': 3}
    ---
    

    BTW:

    Because it gets only 1000 values you may not see 4SNQ... which is at position ~1200 at this moment, but if you use before=

    get_signatures_for_address(address, before='89Tv9s2uMGaoxB8ZF1LV9nGa72GQ9RbkeyCDvfPviWesZ6ajZBFeHsTPfgwjGEnH7mpZa7jQBXAqjAfMrPirHt2')
    

    then it should be at position ~970


    BTW:

    On Solana Explorer you have big button to change Mainnet to Devnet and when you use Devnet then 2AQdpHJ2JpcEgPiATUXjQxA8QmafFegfQwSLWSprPicm also gives 0 items.

    The same on Solana Beach. There is also big button to change Mainnet to Devnet and when you use Devnet then 2AQdpHJ2JpcEgPiATUXjQxA8QmafFegfQwSLWSprPicm gives 0 items.