@@ -18,13 +18,22 @@ class solana_wallets(Extensions):
18
18
def __init__ (
19
19
self ,
20
20
SOLANA_API_URI : str = "https://api.devnet.solana.com" ,
21
- WALLET_ADDRESS : str = None ,
21
+ WALLET_PRIVATE_KEY : str = None ,
22
22
** kwargs ,
23
23
):
24
24
self .SOLANA_API_URI = SOLANA_API_URI
25
25
self .client = Client (SOLANA_API_URI )
26
- self .wallet_address = WALLET_ADDRESS # Stored as a base58 string
27
- self .wallet_keypair = None # This will hold the Keypair if created
26
+
27
+ # If an existing wallet private key is provided, load the keypair
28
+ if WALLET_PRIVATE_KEY :
29
+ # Here we assume the private key is a base58-encoded string.
30
+ # (You might instead have a hex string; adjust as needed.)
31
+ self .wallet_keypair = Keypair .from_base58_string (WALLET_PRIVATE_KEY )
32
+ self .wallet_address = self .wallet_keypair .pubkey ().to_string ()
33
+ else :
34
+ self .wallet_keypair = None
35
+ self .wallet_address = None
36
+
28
37
self .commands = {
29
38
"Create Solana Wallet" : self .create_wallet ,
30
39
"Get Solana Wallet Balance" : self .get_wallet_balance ,
@@ -39,17 +48,19 @@ def __init__(
39
48
"Get Token Price" : self .get_token_price ,
40
49
"Get Wallet Token Accounts" : self .get_wallet_token_accounts ,
41
50
}
51
+ # Additional initialization as needed
42
52
43
53
async def create_wallet (self ):
44
54
"""
45
55
Creates a new Solana wallet by generating a new keypair.
46
- Updates self.wallet_address and self.wallet_keypair .
56
+ This method can be used if no wallet was connected via the init params .
47
57
"""
48
58
new_keypair = Keypair .generate ()
49
59
self .wallet_keypair = new_keypair
50
- # Get the public key as a base58 string:
51
60
self .wallet_address = new_keypair .pubkey ().to_string ()
52
- secret_hex = new_keypair .secret ().hex ()
61
+ secret_hex = (
62
+ new_keypair .secret ().hex ()
63
+ ) # for display; store securely in practice
53
64
return (
54
65
f"Created new Solana wallet.\n "
55
66
f"Public Key: { self .wallet_address } \n "
0 commit comments