For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

铸造NFT

Mint NFT to MCS Opensea Collection

McsAPI.upload_nft_metadata(wallet_address, filename, nft_uri, tx_hash, file_size)

ContractAPI.mint_nft(wallet_address, private_key, meta_url)

The following code example mints an uploaded file as a NFT viewable on Opensea. Create an NFT object and provide the payload_cid of the file. The NFT object follows the Opensea metadata standards.

def test_mint_nft(wallet_info):
    wallet_address = wallet_info['wallet_address']
    private_key = wallet_info['private_key']
    web3_api = wallet_info['web3_api']
    
    w3_api = ContractAPI(web3_api)
    api = McsAPI()

    # upload file to mcs
    file_path = "/i*"
    filename = "/*"
    upload_file = api.upload_file(wallet_address, file_path)
    file_data = upload_file["data"]
    payload_cid, source_file_upload_id, nft_uri, file_size, w_cid = file_data['payload_cid'], file_data[
        'source_file_upload_id'], file_data['ipfs_url'], file_data['file_size'], file_data['w_cid']
    # get the global variable
    params = api.get_params()["data"]
    # get filcoin price
    rate = api.get_price_rate()["data"]
    # test upload_file_pay contract
    tx_hash = w3_api.upload_file_pay(wallet_address, private_key, 
        file_size, w_cid, rate, params)
    # upload nft metadata
    meta_url = api.upload_nft_metadata(wallet_address, filename, 
        nft_uri, tx_hash, file_size)['data']['ipfs_url']
    # mint nft contract
    tx_hash, token_id = w3_api.mint_nft(wallet_address, private_key, meta_url)
    # update mint info
    api.get_mint_info(source_file_upload_id, None, tx_hash, token_id, wallet_address)

Parameters

  • wallet_address: the MetaMask wallet address.

  • private_key: wallet private key

  • meta_url: can be obtained through upload_nft_metadata

Return

Returns the response from the /mint/info API

Last updated