Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

[WIP] Add function to update token metadata #12

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion api/metaplex_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from cryptography.fernet import Fernet
import base58
from solana.account import Account
from metaplex.transactions import deploy, topup, mint, send, burn
from metaplex.transactions import deploy, topup, mint, send, burn, update_token_metadata
from utils.execution_engine import execute

class MetaplexAPI():
Expand Down Expand Up @@ -90,6 +90,24 @@ def mint(self, api_endpoint, contract_key, dest_key, link, max_retries=3, skip_c
# except:
# return json.dumps({"status": 400})

def update_token_metadata(self, api_endpoint, mint_token_id, link, data, creators_addresses, creators_verified, creators_share, max_retries=3, skip_confirmation=False, max_timeout=60, target=20, finalized=True, supply=1 ):
"""
Updates the json metadata for a given mint token id.
"""
tx, signers = update_token_metadata(api_endpoint, self.account, mint_token_id, link, data, creators_addresses, creators_verified, creators_share)
resp = execute(
api_endpoint,
tx,
signers,
max_retries=max_retries,
skip_confirmation=skip_confirmation,
max_timeout=max_timeout,
target=target,
finalized=finalized,
)
resp["status"] = 200
return json.dumps(resp)

def send(self, api_endpoint, contract_key, sender_key, dest_key, encrypted_private_key, max_retries=3, skip_confirmation=False, max_timeout=60, target=20, finalized=True):
"""
Transfer a token on a given network and contract from the sender to the recipient.
Expand Down
25 changes: 25 additions & 0 deletions metaplex/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ def topup(api_endpoint, sender_account, to, amount=None):
return tx, signers


def update_token_metadata(api_endpoint, source_account, mint_token_id, link, data, creators_addresses, creators_verified, creators_share):
"""
Updates the json metadata for a given mint token id.
"""
mint_account = PublicKey(mint_token_id)
signers = [source_account]

tx = Transaction()
update_metadata_data = update_metadata_instruction_data(
data['name'],
data['symbol'],
link,
creators_addresses,
creators_verified,
creators_share,
)
update_metadata_ix = update_metadata_instruction(
update_metadata_data,
source_account.public_key(),
mint_account,
)
tx = tx.add(update_metadata_ix)
return tx, signers


def mint(api_endpoint, source_account, contract_key, dest_key, link, supply=1):
"""
Mint a token on the specified network and contract, into the wallet specified by address.
Expand Down