AUG-2022
How to create a new token account to send token to with solana-py
What you will need: 1. Token Address. It is the unique identifier of your token that is provided to you when you first make it.
from spl.token.instructions import create_associated_token_account
from solana.rpc.commitment import Confirmed
from solana.rpc.api import Client
from solana.rpc.types import TxOpts
from solana.keypair import Keypair
from solana.publickey import PublicKey
from solana.transaction import Transaction
mint_public_id = PublicKey("")
new_wallet = Keypair.generate()
transaction = Transaction()
transaction.add(
create_associated_token_account(
new_wallet.public_key, #who is paying for the creation of this token account?
new_wallet.public_key, #who is the owner of this new token account?
mint_public_id #what tokens should this token account be able to receive?
)
)
client_devnet = Client(endpoint="https://api.devnet.solana.com", commitment=Confirmed)
client_devnet.request_airdrop(new_wallet.public_key,1000000000)
client_devnet.get_balance(new_wallet.public_key)
client_devnet.send_transaction(
transaction, new_wallet, opts=TxOpts(skip_confirmation=False, preflight_commitment=Confirmed))
KEYWORDS: solana-py token account token python create token account with python