Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from solana.rpc.api import Client, Transaction
- from solders.pubkey import Pubkey
- from solana.transaction import AccountMeta
- from solders.instruction import Instruction
- from borsh_construct import CStruct, String, U8, U16, Vec, Option, Bool
- # some important public keys
- system_program = Pubkey.from_string('11111111111111111111111111111111')
- system_rent = Pubkey.from_string('SysvarRent111111111111111111111111111111111')
- token_program = Pubkey.from_string("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
- token_metadata_program = Pubkey.from_string("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
- # my own keypair
- my_keypair = MY_KEYPAIR
- # public key of my token
- new_token = TOKEN_PUBLIC_KEY
- # structure of the instruction
- instruction_structure = CStruct(
- "instructionDiscriminator" / U8,
- "createMetadataAccountArgsV3" / CStruct(
- "data" / CStruct(
- "name" / String,
- "symbol" / String,
- "uri" / String,
- "sellerFeeBasisPoints" / U16,
- "creators" / Option(Vec(CStruct(
- "address" / String,
- "verified" / Bool,
- "share" / U8
- )))
- ),
- "is_mutable" / Bool
- )
- )
- # data for the instruction
- instruction_data = {
- "instructionDiscriminator": 33,
- "createMetadataAccountArgsV3": {
- "data": {
- "name": "My Token Name",
- "symbol": "MTN",
- "uri": "https://arweave.net/somewhere",
- "sellerFeeBasisPoints": 500,
- "creators": [
- {
- "address": str(my_keypair.pubkey()),
- "verified": 1,
- "share": 100
- }
- ],
- },
- "is_mutable": 1
- }
- }
- # get pda of mint account
- metadata_pda = Pubkey.find_program_address([b"metadata", bytes(token_metadata_program), bytes(new_token)], token_metadata_program)[0]
- # account list for instruction
- accounts = [
- AccountMeta(pubkey=metadata_pda, is_signer=False, is_writable=True), # metadata
- AccountMeta(pubkey=new_token, is_signer=False, is_writable=True), # mint
- AccountMeta(pubkey=my_keypair.pubkey(), is_signer=True, is_writable=False), # mint authority
- AccountMeta(pubkey=my_keypair.pubkey(), is_signer=True, is_writable=True), # payer
- AccountMeta(pubkey=my_keypair.pubkey(), is_signer=False, is_writable=False), # update authority
- AccountMeta(pubkey=system_program, is_signer=False, is_writable=False), # system program
- AccountMeta(pubkey=system_rent, is_signer=False, is_writable=False) # rent
- ]
- # create instruction
- instruction = Instruction(token_metadata_program, instruction_structure.build(instruction_data), accounts)
- # send a transaction with the instruction to the network
- client = Client("https://api.devnet.solana.com")
- transaction = Transaction()
- transaction.add(instruction)
- transaction.recent_blockhash = client.get_latest_blockhash().value.blockhash
- transaction.sign(my_keypair)
- print(client.send_raw_transaction(transaction.serialize()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement