Based on reading [https://github.com/solana-labs/solana-program-library/blob/master/token/program/src/instruction.rs#L426][1]
It looks like the Token program does in fact have GetAccountDataSize so I am wondering why the fallowing code
def compile_transaction(owner_wallet: Keypair, instructions: list, latest_blockhash) -> VersionedTransaction:
"""
compiles a simple msg and returns a versioned transaction
"""
msg = MessageV0.try_compile(
payer=owner_wallet.pubkey(),
instructions=instructions,
address_lookup_table_accounts=[],
recent_blockhash=latest_blockhash
)
return VersionedTransaction(message=msg, keypairs=[owner_wallet])
def create_token_account(owner_wallet_path: str, mint_keypair_path: str):
client = Client(CLIENT_ADDRESS)
response = client.get_latest_blockhash()
latest_blockhash = response.value.blockhash
owner_wallet = get_keypair_from_file(owner_wallet_path)
mint_keypair = get_keypair_from_file(mint_keypair_path)
mint_pubkey = mint_keypair.pubkey()
associated_token_address = get_associated_token_address(
owner=owner_wallet.pubkey(),
mint=mint_pubkey
)
print(f'associated_token_address: {associated_token_address}')
# Check if the token account already exists
account_info = client.get_account_info(associated_token_address)
if account_info.value is not None:
raise ValueError(f'Token account {associated_token_address} already exists')
else:
create_token_account_instruction = create_associated_token_account(owner_wallet.pubkey(), owner_wallet.pubkey(), mint_pubkey)
# Create the InitializeAccount instruction
initialize_account_instruction = initialize_account(
InitializeAccountParams(
account=associated_token_address,
mint=mint_pubkey,
owner=owner_wallet.pubkey(),
program_id=TOKEN_PROGRAM_ID
)
)
print(f'The token program is {TOKEN_PROGRAM_ID}')
print(f'The associated token program is {ASSOCIATED_TOKEN_PROGRAM_ID}')
create_account_txn = compile_transaction(owner_wallet, [create_token_account_instruction, initialize_account_instruction], latest_blockhash)
client.send_transaction(create_account_txn)
print(f'Created token account {associated_token_address} for {owner_wallet.pubkey()}')
write_associated_token_account_to_file(associated_token_address, owner_wallet_path)
return associated_token_address
Generates the fallowing error message
solana.rpc.core.RPCException: SendTransactionPreflightFailureMessage { message: "Transaction simulation failed: Error processing Instruction 0: incorrect program id for instruction", data: RpcSimulateTransactionResult(RpcSimulateTransactionResult { err: Some(InstructionError(0, IncorrectProgramId)), logs: Some(["Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]", "Program log: Create", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", "Program log: Instruction: GetAccountDataSize", "Program log: Error: IncorrectProgramId", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 884 of 394486 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: incorrect program id for instruction", "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 6398 of 400000 compute units", "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: incorrect program id for instruction"]), accounts: None, units_consumed: Some(0), return_data: None })
This is on devnet