I want to buy Solana coins and nfts with python and I am not sure, how transactions via the blockchain exactly work. Let's say I want to do this transaction: https://solscan.io/tx/5fzuhifWuBFRPtRGHRRsWsJVHuoxcgEN4USzNBu3ZS8VxwL6Fdw8BFaqU4iAEGibQpEAJyG19QhB335K1HiRtQWX and this is my code:
import solana.system_program as sp
from solana.publickey import PublicKey
from solana.account import Account
from solana.rpc.api import Client
from solana.transaction import Transaction, TransactionInstruction, AccountMeta
# keypair = your key pair
cli = Client('https://solana-api.projectserum.com')
account = Account(keypair[:32])
new_account = Account()
print(new_account.public_key())
print(new_account.keypair())
transaction = Transaction()
transaction.add(sp.create_account(sp.CreateAccountParams(
from_pubkey=account.public_key(),
new_account_pubkey=new_account.public_key(),
lamports=cli.get_minimum_balance_for_rent_exemption(88).get('result'),
space=88,
program_id=PublicKey('CJsLwbP1iu5DuUikHEJnLfANgKy6stB2uFgvBBHoyxwz'),
)))
send_tx = cli.send_transaction(transaction, new_account)
print(send_tx)
I know that I don't have enough solana in my test wallet right now, but it's more about the general way to send transactions and to interact with program ids. There is some Data shown in the sollet.io transaction, but I am not sure, if I have to send that too? And if I have to, where exactly and how do I include that? Does the data change for each transaction? I get the error message:
{'code': -32602, 'message': 'invalid transaction: index out of bounds'}