Library to perform NFT mints automatically on the Cardano blockchain
Project description
cardano-nft-vending-machine
A simple CNFT mint-and-vend machine Python library that leverages cardano-cli
:warning: IMPORTANT
Interactions on the Cardano blockchain involve REAL CURRENCY AND SHOULD NOT BE TREATED LIGHTLY. Some principles:
- Never send money to an address you don't know and can't validate
- Keys should be stored on servers that have as little attack surface (e.g., iptables blacklists) as possible
- Open source software should always be audited -- UTSL!
- There are NO WARRANTIES WHATSOEVER WITH THIS PACKAGE -- use at your own risk
Quickstart
This project contains Library bindings that can be installed using the standard wheel mechanism. See the script quickstart section for how to run from CLI.
Library Usage
The library consists of several Python objects representing the mint process. The sample below shows how one could run an infinite CNFT vending machine on mainnet for a 10₳ mint where users send an extra 2₳ for the rebate:
# The Mint object below represents your Mint policy and specifies price, rebate, and donation in Lovelace
mint = Mint('<POLICY_ID>', 10000000, 2000000, 1000000, '/path/to/nft/json/metadata', '/path/to/mint/script', '/path/to/mint.skey')
# Blockfrost is used in the code to validate where the UTXO sent to the payment address came from
blockfrost_api = BlockfrostApi('<BLOCKFROST_PROJ_ID>', mainnet=True)
# CardanoCli is a wrapper around the cardano-cli command (and uses the CARDANO_NODE_SOCKET_PATH env var)
cardano_cli = CardanoCli(mainnet=True, protocol_params='/path/to/protocol.json')
# NftVendingMachine vends NFTs and needs to be called repeatedly (with a 25-vend max) so long as the mint period is open
nft_vending_machine = NftVendingMachine('addr_payment', '/path/to/payment.skey', 'addr_profit', 25, mint, blockfrost_api, cardano_cli, mainnet=True)
# The following simple loop carries the state of already-completed UTXOs to avoid double spending errors and uses a do-wait-check loop
already_completed = set()
while _program_is_running:
nft_vending_machine.vend('/path/to/output/dir', 'locking_subdir_name', 'metadata_subdir_name', already_completed)
time.sleep(WAIT_TIMEOUT)
cardano_vending_machine.py
There is a sample vending machine script that is included in the src/
directory to show how to invoke the library components. Use -h
to see detailed help or use a command like below:
src/cardano/wt/cardano_vending_machine.py \
--payment-addr <PAYMENT_ADDR> \
--payment-sign-key /FULL/PATH/TO/payment.skey \
--profit-addr <PROFIT_ADDR> \
--mint-price <PRICE_LOVELACE> \
--mint-rebate <REBATE_LOVELACE> \
--mint-script /FULL/PATH/TO/policy.script \
--mint-sign-key /FULL/PATH/TO/policy.skey \
--mint-policy $(cat /FULL/PATH/TO/policyID) \
--blockfrost-project <BLOCKFROST_PROJECT_ID> \
--metadata-dir metadata/ \
--output-dir output/ \
[--single-vend-max <MAX_SINGLE_VEND>] \
[--vend-randomly] \
[--no-donation]
Installation
This package is available from PyPI and can be installed using pip3
. Python <3.8 is currently unsupported at this time.
pip3 install cardano-nft-vending-machine
APIs
All API documentation is auto-generated from pydoc3
-formatted multi-line strings in the source code. A mirror of master
is hosted on Github Pages.
Build
Building this project creates a .whl
file for uploading to PyPI or installing locally on a server. All output is, by default, stored to dist/
. To build, run:
python3 -m build
Test
Tests are stored in the tests
subdirectory and are run using pytest. To invoke the tests:
python3 -m pytest tests
Pull requests to master
require 0 failing tests in order to be merged.
Documentation
Documentation is stored in multi-line comments inside the source code and should be generated using the pdoc3
package as follows:
pdoc3 --html -o docs/ src/cardano
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cardano-nft-vending-machine-0.3.0b3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 307c171f0840c75a787368b41ee944dd4cfbc003bd81da6254dde8011967a998 |
|
MD5 | 4a755d46669a0db46d23203b6640dc3d |
|
BLAKE2b-256 | e5934894e550976a83a53479692b433cce9477b97aedae2112e088ed26b8b1e1 |
Hashes for cardano_nft_vending_machine-0.3.0b3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3c19ee266d46e2bce9f6efb9fccdc6b263cca00e37430134b0250f96de799ae |
|
MD5 | cb104080c71b59b6e91597aa56b9b271 |
|
BLAKE2b-256 | d5f60a47868cf7af51cb2e4bc60238e0389823fbd1a016c4afe9a65f2462e0ca |