Solana: Sending SOL in Python with Solders from a JSON file
Here is the article on how to send the sun from Json File Wesing the Solders Library and Python:
Submitting Sol from a JSON file with welds
In this article, we will explore how to weld in Python welds to transfer all sun from different walls located in a .json fillet to a single WALET destination.
Pre -Requisites
Before WES, make sure you have the following installed:
- Python 3.6+
- Solders Library (
Pip installed welds')
- A Files Name of Walet JsonWallets.json
Decrease the JSON file structure
*
There is a Phille Walet Json must be structured as follows:
Json
[[
{
"Ddequency": "0x ...."
"Balance": 1000,
"Tag": "Test"
},
{
"Ddequency": "0x ...."
"Balance": 500,
"Tag": "Another test"
}
]
re
In this example, tired wrets with the addition of0x …and balances 1000 and 500, respectively. The
tag property is not used to identify the wall.
Python Function
Here is a python function that from transfers all sun from different walls to a single destination wallet:
`Python
Import of solids
DEF Transfer_Sols (wallets, destination_addrress):
"" "
Transfers all sun to different wallets to a single destination wall.
Parameters:
Walllets (List): List the wall dictionaries
Destination_Address (STR): destination destination.
Returns:
None
"" "
Create a welding customer
Customer = Solid.SoldsClient ()
Free load waletts
wings_data = {}
with Open ('Json', 'R') as F:
for in f.readlines ():
wing_data = json.loads (line)
If Walet_Data ['Adddress'] = = destination_address:
wings_data [destination_address] = wallet_data
Transfer Sol Aggansnse Wreck to the destination addresses
For Walet in Walts_Data.valuate ():
clinical
Free load waletts
with Open ('Json', 'R') as F:
Wings = json.loads (f.readlines ())
Send Sol to a single destination wallet
destination_addrress = '0x ...'
Transfer_Soles (wallets, destination_address)
Print ("Sun Transfered Successful!")
re
Explanation
In this, we cannot be customers and loads of theWallets.json file in memory. We are the wallet of the list on the walls, checking your destination.
Example
Let’s say you have WAILTS toy with address 0x ...
and 0x ...
. You want to travel all the sun to a single destination wall 0x ...
.
Listening to List a Woeld Create for Dictionary Waves, carry them in the surviving memory of the Transfer_Sols' function:
Python
Wings =
{
"Ddequency": "0x ...."
"Balance": 1000,
"Tag": "Test"
},
{
"Ddequency": "0x ...."
"Balance": 500,
"Tag": "Another test"
}
]
destination_addrress = '0x ...'
Transfer_Soles (wallets, destination_address)
re
That way, transfer all sun from them to them destination attachments0x …`.
The intelligence has been realized that is the fillet JSON is already a stairs and is available. If you need to deliver a large number of complex Walets or Walet data, you can be a more efficient data structure or cache mechanism.