I managed to send some USDC-dev
token on the devnet with the following code.
Is there a way to send more than 1 transaction with something like Transaction.add()
Here is the working code for 1 transaction
from solana.rpc.api import Client
from spl.token.client import Token
from solders.pubkey import Pubkey
from solders.keypair import Keypair
from solders.system_program import TransferParams, transfer
from solana.transaction import Transaction
mint = Pubkey.from_string(
"Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr"
) # eg: https://solscan.io/token/FpekncBMe3Vsi1LMkh6zbNq8pdM6xEbNiFsJBRcPbMDQ**
program_id = Pubkey.from_string(
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
) # eg: https://solscan.io/account/**TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA**
privkey = "6614rQjZYrcUL8YtNQ8vcf.......VM8hJwgMPnSPdBRGHSxxroJLn"
key_pair = Keypair.from_base58_string(privkey)
solana_client = Client("https://api.devnet.solana.com")
spl_client = Token(
conn=solana_client, pubkey=mint, program_id=program_id, payer=key_pair
)
source = Pubkey.from_string("BAPkhTqGe4Squ8hH71QzixhTcfhJv7Lb8SvV7To5gzPg")
dest = Pubkey.from_string("3ApghjTLzyAfBvq9z1kQkfTp5puoZHsKZZ9ziwBvR8T1")
try:
source_token_account = (
spl_client.get_accounts_by_owner(
owner=source, commitment=None, encoding="base64"
)
.value[0]
.pubkey
)
except:
source_token_account = spl_client.create_associated_token_account(
owner=source, skip_confirmation=False, recent_blockhash=None
)
try:
dest_token_account = (
spl_client.get_accounts_by_owner(owner=dest, commitment=None, encoding="base64")
.value[0]
.pubkey
)
except:
dest_token_account = spl_client.create_associated_token_account(
owner=dest, skip_confirmation=False, recent_blockhash=None
)
amount = 10
txn = Transaction()
transaction = spl_client.transfer(
source=source_token_account,
dest=dest_token_account,
owner=key_pair,
amount=int(float(amount) * 100000),
multi_signers=None,
opts=None,
recent_blockhash=None,
)
print(transaction)