Example #1
0
def destroy(params_dict):
    algod_client, params = algod_connect(params_dict)
    print(
        '\n=====================================DESTROY ASSET====================================='
    )
    print('asset id:', params_dict['asset'])

    # For destroy an asset, the account need to have all unites of the named asset
    # The sender have to be the manager account
    txn = AssetConfigTxn(sender=params_dict['sender'],
                         sp=params,
                         index=params_dict['asset'],
                         strict_empty_address_check=False)

    private_key = mnemonic.to_private_key(params_dict['mnemonic'])
    stxn = txn.sign(private_key)

    txid = algod_client.send_transaction(stxn)
    print('Transaction ID:', txid)

    wait_for_confirmation(algod_client, txid)

    try:
        print_asset_holding(algod_client, params_dict['sender'],
                            params_dict['asset'])
        print_asset_created(algod_client, params_dict['sender'],
                            params_dict['asset'])
    except Exception as e:
        print(e)
Example #2
0
def destroyAsset(algod_client, alice, asset_id, bob):
    print("--------------------------------------------")
    print("Destroying Alice's token......")
    params = algod_client.suggested_params()
    # comment these two lines if you want to use suggested params
    # params.fee = 1000
    # params.flat_fee = True

    # Asset destroy transaction
    txn = AssetConfigTxn(sender=alice['pk'],
                         sp=params,
                         index=asset_id,
                         strict_empty_address_check=False)

    # Sign with secret key of creator
    stxn = txn.sign(alice['sk'])
    # Send the transaction to the network and retrieve the txid.
    txid = algod_client.send_transaction(stxn)
    print(txid)
    # Wait for the transaction to be confirmed
    confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
    print("TXID: ", txid)
    print("Result confirmed in round: {}".format(
        confirmed_txn['confirmed-round']))
    print("Alice's Token is destroyed.")
Example #3
0
def mint_official_nft(swarm_hash: str, is_public: bool, username: str, title: str, number: int,
                      asset_symbol: str = 'MYPIC', asset_name: str = 'MyPic NFT', website_url: str = 'http://mypic.io'):
    params = algod_client.suggested_params()
    params.fee = 1000
    params.flat_fee = True

    data_set = {"is_public": f'{is_public}', 'username': username, 'title': title, 'number': f'{number}'}

    tx_note_json_str = json.dumps(data_set)
    tx_note_bytes = tx_note_json_str.encode("utf-8")
    swarm_hash_bytes = unhexlify(swarm_hash)
    txn = AssetConfigTxn(sender=accounts[1]['pk'],
                         sp=params,
                         total=1,
                         decimals=0,
                         unit_name=asset_symbol,
                         asset_name=asset_name,
                         strict_empty_address_check=False,
                         default_frozen=False,
                         metadata_hash=swarm_hash_bytes,
                         note=tx_note_bytes,
                         manager=accounts[1]['pk'],
                         reserve=accounts[1]['pk'],
                         freeze="",
                         clawback=accounts[1]['pk'],
                         url=website_url)

    stxn = txn.sign(accounts[1]['sk'])
    tx_id = algod_client.send_transaction(stxn)
    wait_for_confirmation(tx_id)
    ptx = algod_client.pending_transaction_info(tx_id)
    asset_id = ptx["asset-index"]
    return asset_id
Example #4
0
def create_asset(payload):
    asset_details = process_payload(payload)
    # Get network params for transactions before every transaction.
    params = algod_client.suggested_params()
    params.fee = 10
    params.flat_fee = True

    # Account 1 creates an asset called latinum and
    # sets Account 2 as the manager, reserve, freeze, and clawback address.
    # Asset Creation transaction

    txn = AssetConfigTxn(
        sender=accounts[1]['pk'],
        sp=params,
        total=asset_details['issue_size'],
        default_frozen=False,
        unit_name=asset_details['bond_name'].upper(),
        asset_name=asset_details['bond_name'],
        manager=accounts[1]['pk'],
        reserve=accounts[1]['pk'],
        freeze=accounts[1]['pk'],
        clawback=accounts[1]['pk'],
        # url="https://path/to/my/asset/details",
        decimals=0,
        metadata_hash=asset_details['metadata_hash'].encode('ascii'))
    # Sign with secret key of creator
    stxn = txn.sign(accounts[1]['sk'])

    # Send the transaction to the network and retrieve the txid.
    txid = algod_client.send_transaction(stxn)
    print(txid)

    # Retrieve the asset ID of the newly created asset by first
    # ensuring that the creation transaction was confirmed,
    # then grabbing the asset id from the transaction.

    # Wait for the transaction to be confirmed
    wait_for_confirmation(algod_client, txid)

    try:
        # Pull account info for the creator
        # account_info = algod_client.account_info(accounts[1]['pk'])
        # get asset_id from tx
        # Get the new asset's information from the creator account
        ptx = algod_client.pending_transaction_info(txid)
        asset_id = ptx["asset-index"]
        print_created_asset(algod_client, accounts[1]['pk'], asset_id)
        print_asset_holding(algod_client, accounts[1]['pk'], asset_id)
    except Exception as e:
        print(e)

    return asset_id
def createAsset(algod_client, passphrase, html, doc_id, doc_name):
    # CREATE ASSET
    # Get network params for transactions before every transaction.
    params = algod_client.suggested_params()
    # comment these two lines if you want to use suggested params
    params.fee = 1000
    params.flat_fee = True

    # Account 1 creates an asset called latinum and
    # sets Account 2 as the manager, reserve, freeze, and clawback address.
    # Asset Creation transaction
    account_pk = mnemonic.to_public_key(passphrase)
    account_sk = mnemonic.to_private_key(passphrase)
    txn = AssetConfigTxn(sender=account_pk,
                         sp=params,
                         total=1,
                         default_frozen=False,
                         unit_name=doc_id,
                         asset_name=doc_name,
                         manager=account_pk,
                         reserve=account_pk,
                         freeze=account_pk,
                         clawback=account_pk,
                         url=html,
                         decimals=0)
    # Sign with secret key of creator
    stxn = txn.sign(account_sk)

    # Send the transaction to the network and retrieve the txid.
    txid = algod_client.send_transaction(stxn)
    print(txid)

    # Retrieve the asset ID of the newly created asset by first
    # ensuring that the creation transaction was confirmed,
    # then grabbing the asset id from the transaction.

    # Wait for the transaction to be confirmed
    wait_for_confirmation(algod_client, txid)

    try:
        # Pull account info for the creator
        # account_info = algod_client.account_info(accounts[1]['pk'])
        # get asset_id from tx
        # Get the new asset's information from the creator account
        ptx = algod_client.pending_transaction_info(txid)
        asset_id = ptx["asset-index"]
        print_created_asset(algod_client, account_pk, asset_id)
        print_asset_holding(algod_client, account_pk, asset_id)
    except Exception as e:
        print(e)
Example #6
0
def create(params_dict):
    algod_client, params = algod_connect(params_dict)
    print(
        '\n=====================================CREATE ASSET====================================='
    )
    # Create an asset with the parameters params_dict

    # For each created or owned asset it is necessary to have a minimum balance on the account of -
    # -> 100,000 microAlgos

    txn = AssetConfigTxn(sender=params_dict['sender'],
                         sp=params,
                         total=params_dict['total'],
                         default_frozen=params_dict['default_frozen'],
                         unit_name=params_dict['unit_name'],
                         asset_name=params_dict['asset_name'],
                         manager=params_dict['manager'],
                         reserve=params_dict['reserve'],
                         freeze=params_dict['freeze'],
                         clawback=params_dict['clawback'],
                         decimals=params_dict['decimals'])

    private_key = mnemonic.to_private_key(params_dict['mnemonic'])

    # Sign transaction
    stxn = txn.sign(private_key)

    # Send signed transaction to the network and recover its ID
    txid = algod_client.send_transaction(stxn)
    print('Transaction ID: ', txid)

    wait_for_confirmation(algod_client, txid)

    try:
        ptx = algod_client.pending_transaction_info(txid)
        asset_id = ptx['asset-index']
        print_asset_created(algod_client, params_dict['sender'], asset_id)
        print_asset_holding(algod_client, params_dict['sender'], asset_id)
    except Exception as e:
        print(e)

    return asset_id
Example #7
0
def create_asset(algod_client, holder, name, url, amount, note=''):
    """
    @params{algod_client} - AlgodClient instance created by calling algod.AlgodClient
    @params{holder} - a dictionary containing the public/private key of the holder
                    - { 'public_key': string, 'private_key': string }
    @params{name} - a string of asset name
    @params{url} - a string of the url of the targeted auction page
    @params{amount} - an int of the number of assets to create
    @params{note} OPTIONAL - a string of note to put in the transaction
    Creates an asset with the given amount as NFTs to sell.
    @returns {
        'status': boolean,
        'asset_id': int,
        'info': json string containing the transaction information if status is True else a string of error message
    }
    """
    params = algod_client.suggested_params()
    params.flat_fee = True
    params.fee = 1000
    unsigned_txn = AssetConfigTxn(
        sender=holder['public_key'], sp=params, total=amount, default_frozen=False,
        unit_name='NFT', asset_name=name, manager=holder['public_key'],
        reserve=holder['public_key'], freeze=holder['public_key'], clawback=holder['public_key'],
        url=url, decimals=0)
    signed_txn = unsigned_txn.sign(holder['private_key'])
    txid = algod_client.send_transaction(signed_txn)
    print('Pending transaction with id: {}'.format(txid))
    try:
        confirmed_txn = wait_for_confirmation(algod_client, txid)
        print_created_asset(algod_client, holder['public_key'], confirmed_txn['asset-index'])
        print_asset_holding(algod_client, holder['public_key'], confirmed_txn['asset-index'])
    except Exception as err:
        print(err)
        return { 'status': False, 'txid': txid, 'info': getattr(err, 'message', str(err)) }
    return {
        'status': True,
        'asset_id': confirmed_txn['asset-index'],
        'info': json.dumps(confirmed_txn)
    }
Example #8
0
def par_token_issuance(algod_client, passphrase, proj_name, vol,
                       url) -> (int, int):
    """
    Issues Token for Par Value Payment
    returns an AssetConfigTxn()
    """

    # sets basic transaction parameter
    params = algod_client.suggested_params()
    params.fee = 1000
    params.flat_fee = True

    address = mnemonic.to_public_key(passphrase)
    key = mnemonic.to_private_key(passphrase)

    # configure asset basics
    txn = AssetConfigTxn(sender=address,
                         sp=params,
                         total=vol,
                         default_frozen=False,
                         unit_name=proj_name[0] + "PC",
                         asset_name=proj_name + "Par",
                         manager=address,
                         reserve=address,
                         freeze=address,
                         clawback=address,
                         url=url,
                         decimals=0)
    signed = txn.sign(key)
    txid = algod_client.send_transaction(signed)
    wait_for_confirmation(algod_client, txid, 4)
    try:
        ptx = algod_client.pending_transaction_info(txid)
        asset_id = ptx["asset-index"]
        return txid, asset_id
    except Exception as e:
        print(e)
Example #9
0
def edit(params_dict):
    algod_client, params = algod_connect(params_dict)
    print(
        '\n=====================================EDIT ASSET====================================='
    )
    print('asset id:', params_dict['asset'])
    txn = AssetConfigTxn(sender=params_dict['sender'],
                         sp=params,
                         index=params_dict['asset'],
                         manager=params_dict['manager'],
                         reserve=params_dict['reserve'],
                         freeze=params_dict['freeze'],
                         clawback=params_dict['clawback'])

    private_key = mnemonic.to_private_key(params_dict['mnemonic'])

    stxn = txn.sign(private_key)
    txid = algod_client.send_transaction(stxn)
    print('Transaction ID: ', txid)

    wait_for_confirmation(algod_client, txid)
    # Print the asset after the confirmation of the transaction
    print_asset_created(algod_client, params_dict['sender'],
                        params_dict['asset'])
Example #10
0
def create_non_fungible_token():
    # For ease of reference, add account public and private keys to
    # an accounts dict.
    print("--------------------------------------------")
    print("Creating account...")
    accounts = {}
    m = create_account()
    accounts[1] = {}
    accounts[1]['pk'] = mnemonic.to_public_key(m)
    accounts[1]['sk'] = mnemonic.to_private_key(m)

    # Change algod_token and algod_address to connect to a different client
    algod_token = "2f3203f21e738a1de6110eba6984f9d03e5a95d7a577b34616854064cf2c0e7b"
    algod_address = "https://academy-algod.dev.aws.algodev.network/"
    algod_client = algod.AlgodClient(algod_token, algod_address)

    print("--------------------------------------------")
    print("Creating Asset...")
    # CREATE ASSET
    # Get network params for transactions before every transaction.
    params = algod_client.suggested_params()
    # comment these two lines if you want to use suggested params
    # params.fee = 1000
    # params.flat_fee = True

    # JSON file
    dir_path = os.path.dirname(os.path.realpath(__file__))
    f = open(dir_path + '/aliceNFTmetadata.json', "r")

    # Reading from file
    metadataJSON = json.loads(f.read())
    metadataStr = json.dumps(metadataJSON)

    hash = hashlib.new("sha512_256")
    hash.update(b"arc0003/amj")
    hash.update(metadataStr.encode("utf-8"))
    json_metadata_hash = hash.digest()

    # Account 1 creates an asset called latinum and
    # sets Account 1 as the manager, reserve, freeze, and clawback address.
    # Asset Creation transaction
    txn = AssetConfigTxn(sender=accounts[1]['pk'],
                         sp=params,
                         total=1,
                         default_frozen=False,
                         unit_name="ALICE001",
                         asset_name="Alice's Artwork 001",
                         manager=accounts[1]['pk'],
                         reserve=None,
                         freeze=None,
                         clawback=None,
                         strict_empty_address_check=False,
                         url="https://path/to/my/asset/details",
                         metadata_hash=json_metadata_hash,
                         decimals=0)

    # Sign with secret key of creator
    stxn = txn.sign(accounts[1]['sk'])

    # Send the transaction to the network and retrieve the txid.
    txid = algod_client.send_transaction(stxn)
    print("Asset Creation Transaction ID: {}".format(txid))

    # Wait for the transaction to be confirmed
    confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
    print("TXID: ", txid)
    print("Result confirmed in round: {}".format(
        confirmed_txn['confirmed-round']))
    try:
        # Pull account info for the creator
        # account_info = algod_client.account_info(accounts[1]['pk'])
        # get asset_id from tx
        # Get the new asset's information from the creator account
        ptx = algod_client.pending_transaction_info(txid)
        asset_id = ptx["asset-index"]
        print_created_asset(algod_client, accounts[1]['pk'], asset_id)
        print_asset_holding(algod_client, accounts[1]['pk'], asset_id)
    except Exception as e:
        print(e)

    print("--------------------------------------------")
    print(
        "You have successfully created your own Non-fungible token! For the purpose of the demo, we will now delete the asset."
    )
    print("Deleting Asset...")

    # Asset destroy transaction
    txn = AssetConfigTxn(sender=accounts[1]['pk'],
                         sp=params,
                         index=asset_id,
                         strict_empty_address_check=False)

    # Sign with secret key of creator
    stxn = txn.sign(accounts[1]['sk'])
    # Send the transaction to the network and retrieve the txid.
    txid = algod_client.send_transaction(stxn)
    print("Asset Destroy Transaction ID: {}".format(txid))

    # Wait for the transaction to be confirmed
    confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
    print("TXID: ", txid)
    print("Result confirmed in round: {}".format(
        confirmed_txn['confirmed-round']))
    # Asset was deleted.
    try:
        print_asset_holding(algod_client, accounts[1]['pk'], asset_id)
        print_created_asset(algod_client, accounts[1]['pk'], asset_id)
        print("Asset is deleted.")
    except Exception as e:
        print(e)

    print("--------------------------------------------")
    print("Sending closeout transaction back to the testnet dispenser...")
    closeout_account(algod_client, accounts[1])
Example #11
0
def create_asset(alice):
  # accounts = dictionary holding public key, secret key of accounts.
  # Change algod_token and algod_address to connect to a different client
  algod_token = "2f3203f21e738a1de6110eba6984f9d03e5a95d7a577b34616854064cf2c0e7b"
  algod_address = "https://academy-algod.dev.aws.algodev.network/"
  algod_client = algod.AlgodClient(algod_token, algod_address)

  print("--------------------------------------------")
  print("Creating Asset...")
  # CREATE ASSET
  # Get network params for transactions before every transaction.
  params = algod_client.suggested_params()
  # comment these two lines if you want to use suggested params
  # params.fee = 1000
  # params.flat_fee = True

  # JSON file
  dir_path = os.path.dirname(os.path.realpath(__file__))
  f = open (dir_path + '/aliceAssetMetaData.json', "r")
  
  # Reading from file
  metadataJSON = json.loads(f.read())
  metadataStr = json.dumps(metadataJSON)

  hash = hashlib.new("sha512_256")
  hash.update(b"arc0003/amj")
  hash.update(metadataStr.encode("utf-8"))
  json_metadata_hash = hash.digest()

  # Account 1 creates an asset called ALICEOI and
  # sets Account 1 as the manager, reserve, freeze, and clawback address.
  # Asset Creation transaction
  txn = AssetConfigTxn(
      sender=alice['pk'],
      sp=params,
      total=1000,
      default_frozen=False,
      unit_name="ALICEOI",
      asset_name="Alice's Artwork Coins@arc3",
      manager=alice['pk'],
      reserve=alice['pk'],
      freeze=alice['pk'],
      clawback=alice['pk'],
      url="https://path/to/my/asset/details", 
      metadata_hash=json_metadata_hash,
      decimals=0)

  # Sign with secret key of creator
  stxn = txn.sign(alice['sk'])

  # Send the transaction to the network and retrieve the txid.
  txid = algod_client.send_transaction(stxn)
  print("Asset Creation Transaction ID: {}".format(txid))

  # Wait for the transaction to be confirmed
  confirmed_txn = wait_for_confirmation(algod_client, txid, 4)
  print("TXID: ", txid)
  print("Result confirmed in round: {}".format(confirmed_txn['confirmed-round']))
  try:
      # Pull account info for the creator
      # account_info = algod_client.account_info(accounts[1]['pk'])
      # get asset_id from tx
      # Get the new asset's information from the creator account
      ptx = algod_client.pending_transaction_info(txid)
      asset_id = ptx["asset-index"]
      print_created_asset(algod_client, alice['pk'], asset_id)
      print_asset_holding(algod_client, alice['pk'], asset_id)
  except Exception as e:
      print(e)
  
  return asset_id
Example #12
0
txn = AssetConfigTxn(
    sender=accounts[1]['pk'],
    sp=params,
    total=1000,
    default_frozen=False,
    unit_name="LATINUM",
    asset_name="latinum",
    manager=accounts[2]['pk'],
    reserve=accounts[2]['pk'],
    freeze=accounts[2]['pk'],
    clawback=accounts[2]['pk'],
    url="https://path/to/my/asset/details", 
    decimals=0)
# Sign with secret key of creator
stxn = txn.sign(accounts[1]['sk'])

# Send the transaction to the network and retrieve the txid.
try:
    txid = algod_client.send_transaction(stxn)
    print("Signed transaction with txID: {}".format(txid))
    # Wait for the transaction to be confirmed
    confirmed_txn = wait_for_confirmation(algod_client, txid, 4)  
    print("TXID: ", txid)
    print("Result confirmed in round: {}".format(confirmed_txn['confirmed-round']))
   
except Exception as err:
    print(err)
# Retrieve the asset ID of the newly created asset by first
# ensuring that the creation transaction was confirmed,
# then grabbing the asset id from the transaction.