1

I am running into some issues when trying to create tokens using solana-py, I have seen the python functions for the SPL client but I don't really know how to use it. For instance, how could I replicate the following Solana CLI actions using solana-py:

spl-token create-token
spl-token create-account <TOKEN>
spl-token mint <TOKEN> 100

Peter Schwarz
  • 231
  • 2
  • 10

3 Answers3

1

Your best bet will be to read through the tests to see how it's used.

If you find these too complicated, since they're using a helper class, the stake pool program has some wrappers which may make this clearer.

From there, you should be able to piece together all three actions that you're trying to perform.

Jon C
  • 7,019
  • 10
  • 17
0

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

Koops
  • 422
  • 3
  • 11
0

Hello if you still struggle to create a token on Solana Blockchain, some website UI allows you to create your without any coding knowledge like :

Skelt
  • 1