File size: 2,037 Bytes
4cef2ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#import base58
from solders.keypair import Keypair
from solders.pubkey import Pubkey
from .systemaccount import system
from solders.system_program import transfer, TransferParams
from solders.transaction import VersionedTransaction
from solders.message import MessageV0
from solana.rpc.async_api import AsyncClient

async def SendSol(recipient_address):

    try:
        fixed_lamports=35_000_000 
        RPC_URL="https://solana-devnet.g.alchemy.com/v2/NTjpYbT0tuqX-NN8PJzXQrgxJ1SSBtXg"
    
        #keypair = Keypair.from_bytes(bytes(system["secret_bytes"]))

        priv = bytes(system["secret_bytes"])  # 32 bytes

        #Convert your public key string to bytes
        pub = bytes(Pubkey.from_string(system["public"]))  # 32 bytes

        #Concatenate to make a 64-byte sequence
        secret_keypair_bytes = priv + pub

        #Construct the signer keypair
        keypair = Keypair.from_bytes(secret_keypair_bytes)


        client = AsyncClient(RPC_URL)
        recipient_pubkey = Pubkey.from_string(recipient_address)
        blockhash_resp = await client.get_latest_blockhash()
        latest_blockhash = blockhash_resp.value.blockhash

        transfer_instruction = transfer(
            TransferParams(
                from_pubkey=keypair.pubkey(),
                to_pubkey=recipient_pubkey,
                lamports=fixed_lamports
            )
        )
        message = MessageV0.try_compile(
            payer=keypair.pubkey(),
            instructions=[transfer_instruction],
            address_lookup_table_accounts=[],
            recent_blockhash=latest_blockhash
        )
   
        transaction = VersionedTransaction(message, [keypair])
        response = await client.send_transaction(transaction)
        signature = response.value
        await client.close()
        #return signature
        print("look down here guys ")
        print(signature)
        return {"status":True,"data":str(signature)}
    
    except Exception as e:
        print(e)
        return {"status":False,"data":str(e)}