3

Many projects either use a vending-machine service like NFT-Maker PRO or buffybot or have built their own vending-machine scripts.

Is there any open-source vending machine script that can be connected to a cardano-node to mint NFTs when a UTxO arrives on a specific address?

3 Answers 3

5

Here is my version of a vending machine:

  • Upgraded with metadata creation
  • "Completed" counter backed up in a *.txt file so if the machine restarts the script does not start minting from the beginning
  • You should create your own Blockfrost project
  • Picture uploaded to Infura
  • Sorry for the Hungarian comments
#!/bin/bash

cd /opt/cardano/cnode/priv/wallet/cpostal
looping=1
log=log_file.txt
txs=txs.txt
numberCompleted=`cat numbercompleted.txt`

# ez lesz raymond címe, most a sajátom
donationAddr=`cat rajmond_yoroi_address`

# erre a címre várjuk a befizetéseket
paymentAddr=`cat payment.addr`

paymentSignKeyPath=./payment.skey
policySignKeyPath=./policy/policy.skey
scriptPath=./policy/policy.ada.2.120.script

POLICYID=$(cardano-cli transaction policyid --script-file $scriptPath) > policy/policyID

# ez az én yoroi-s stake címem
profitAddr=`cat yoroi_address`

echo "" >> $txs
echo "" >> $log
echo "Log File" >> $log
echo "-------------------" >> $log
echo "Process started at: $(date +%T)" >> $log
echo "-------------------" >> $log
echo "" >> $log

arcedula=50000000 # ennyit kérünk ezért az NFT-ért

trap 'looping=0;wait' INT TERM

while (( looping )); do
    echo ================================================================================== 
    cardano-cli query utxo --address $paymentAddr --mainnet > fullUtxo.out
    tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
    cat balance.out
    while read -r utxo; do
        sleep 5s
    #echo "UTXO detected" >> $log
        tx_hash=$(awk '{ print $1 }' <<< "${utxo}")
    echo "TXHash: "$tx_hash
    idx=$(awk '{ print $2 }' <<< "${utxo}")
        utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
    tx_in="--tx-in ${tx_hash}#${idx}"
    if [ $( grep -q "${tx_hash}" "$txs" && echo $? ) ];
    then
       # echo "Previous tx" >> $log
        echo "nem trténr  utalás"
        break
    else
        echo ${tx_hash} >> $txs
        echo "utalás trtént"
        echo "A küldő cím: " >> $log
        echo $(curl -H 'project_id: *********' \
                https://cardano-mainnet.blockfrost.io/api/v0/txs/${tx_hash}/utxos \
                | jq '.inputs' | jq '.[0]' | jq '.address') >> $log
            in_addr=$(curl -H 'project_id: *********' \
                https://cardano-mainnet.blockfrost.io/api/v0/txs/${tx_hash}/utxos \
                | jq '.inputs' | jq '.[0]' | jq '.address' | sed 's/^.//;s/.$//')
            echo "Address: ${in_addr}"
        echo "utalás értéke: "$utxo_balance
            if [ ${utxo_balance} != $arcedula ] || [ $(ls "/opt/cardano/cnode/stamps/s1/" | wc -l) == 0 ];
            then
            echo ${utxo_balance} >> $log
            echo "Refund Initiated..." >> $log
        echo `date` >> $log
        echo "Pénzvisszafizetés"
            currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
                cardano-cli transaction build-raw \
                    --fee 0 \
                    ${tx_in} \
                    --tx-out ${in_addr}+${utxo_balance} \
                    --invalid-hereafter $(( ${currentSlot} + 1000)) \
                    --out-file tx.tmp >> $log
                fee=$(cardano-cli transaction calculate-min-fee \
                    --tx-body-file tx.tmp \
                    --tx-in-count 1 \
                    --tx-out-count 1 \
                    --mainnet \
                    --witness-count 1 \
                    --byron-witness-count 0 \
                    --protocol-params-file protocol.json | awk '{ print $1 }') >> $log
                echo "Fee:"$fee >> $log
        fee=${fee%" Lovelace"}
                amountToSendUser=$(( ${utxo_balance}-${fee} ))
            echo ${amountToSendUser} >> $log
                cardano-cli transaction build-raw \
                    --fee ${fee} \
                     ${tx_in} \
                    --tx-out ${in_addr}+${amountToSendUser} \
                    --invalid-hereafter $(( ${currentSlot} + 1000)) \
                    --out-file tx.raw >> $log
echo "Pénz visszküldés submit" >> $log
         cardano-cli transaction sign \
                    --signing-key-file $paymentSignKeyPath \
                    --tx-body-file tx.raw \
                    --out-file tx.signed \
                    --mainnet >> $log
echo "Pénz visszaküldés submit" >> $log
                cardano-cli transaction submit --tx-file tx.signed --mainnet >> $log


# *******************************************NFT MINT *************************************
            else
            echo ========================================================= >> $log
        echo ======================== ÚJ NFT ========================= >> $log
        echo ========================================================= >> $log
        echo "Sending NFT..." >> $log
        echo `date` >> $log
            numberCompleted=$(( numberCompleted+1 ))
        echo "Token száma: $numberCompleted" >> $log
        echo $numberCompleted > numbercompleted.txt
#           POLICYID=$(cardano-cli transaction policyid --script-file $scriptPath) ezt beépítetem az elejére, de ha minden nFT küln policit kapna akkor ide kell


#*********************** metadata gerebléyzés *****************

  tokenname=`cat /opt/cardano/cnode/stamps/s1/Stamp_Ada_$numberCompleted.png.ipfs.txt | awk -F'"' {'print $4 '} | awk -F'.' {'print $1'} | sed -e 's/_//g'`
tokennameID=`cat /opt/cardano/cnode/stamps/s1/Stamp_Ada_$numberCompleted.png.ipfs.txt | awk -F'"' {'print $4 '} | awk -F'_' {'print $3'} | awk -F'.' {'print $1'} | sed 's/^0*//'`
  ipfs_hash=`cat /opt/cardano/cnode/stamps/s1/Stamp_Ada_$numberCompleted.png.ipfs.txt | awk -F'"' {'print $8 '}`
echo "tokenname:" $tokenname >> $log
echo "tokennameID:" $tokennameID >> $log
echo "Poolpm név:"$POLICYID"."$tokenname >> $log


echo "{">> $tokenname"metadata.json"
echo "      \"721\": { ">> $tokenname"metadata.json"
echo "           \"$POLICYID\": { ">> $tokenname"metadata.json"
echo "              \"$tokenname\": { ">> $tokenname"metadata.json"
echo "                \"description\": \"CARDANO POSTAL SERVICE STAMP\"," >> $tokenname"metadata.json"
echo "                \"name\": \"Ada Lovelace stamp $tokennameID\"," >> $tokenname"metadata.json" 
echo "                \"id\": $tokennameID, ">> $tokenname"metadata.json"
echo "                \"creator\": \"Ildiko Kovacs\"," >> $tokenname"metadata.json"
echo "                \"image\": \"ipfs://$ipfs_hash\"," >> $tokenname"metadata.json"
echo "                \"url\": \"https://cardanopostalservice.io\"" >> $tokenname"metadata.json"
echo "              }" >> $tokenname"metadata.json"
echo "            }">> $tokenname"metadata.json"
echo "        }" >> $tokenname"metadata.json"
echo "}">> $tokenname"metadata.json"
metadatajson="${tokenname}metadata.json"

echo ================
echo "mintelési adatok"
echo "tokenname:" $tokenname 
echo "tokennameID:" $tokennameID 
#cat $metadatajson

# **************** Bevétel szétdobása ********************

       amountToSendUser=1800000
((amountToDonate = arcedula * 5 / 100)) # ez magy rajmondnak
    
((amountToSendProfit = arcedula - amountToDonate - amountToSendUser))  # ez megy szabinak

echo 'vegleges szamok:'
echo 'arcedula:' $arcedula
echo 'amount to send profit:' $amountToSendProfit
echo 'amount to send user:' $amountToSendUser
echo 'amount to donate:' $amountToDonate

                currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
                cardano-cli transaction build-raw \
                    --fee 0 \
                    ${tx_in} \
                    --tx-out ${in_addr}+${amountToSendUser}+"1 $POLICYID.${tokenname}" \
                    --tx-out ${profitAddr}+${amountToSendProfit} \
            --tx-out ${donationAddr}+${amountToDonate} \
            --mint="1 $POLICYID.${tokenname}" \
            --minting-script-file $scriptPath \
            --metadata-json-file ${metadatajson} \
                    --invalid-hereafter $(( ${currentSlot} + 10000)) \
                    --out-file tx.tmp >> $log
                fee=$(cardano-cli transaction calculate-min-fee \
                    --tx-body-file tx.tmp \
                    --tx-in-count 1 \
                    --tx-out-count 3 \
                    --mainnet \
                    --witness-count 2 \
                    --byron-witness-count 0 \
                    --protocol-params-file protocol.json | awk '{ print $1 }') >> $log
            fee=${fee%" Lovelace"}
                amountToSendUser=$((${amountToSendUser}-${fee}))
                cardano-cli transaction build-raw \
                    --fee ${fee} \
                    ${tx_in} \
                    --tx-out ${in_addr}+${amountToSendUser}+"1 $POLICYID.${tokenname}" \
                    --tx-out ${profitAddr}+${amountToSendProfit} \
            --tx-out ${donationAddr}+${amountToDonate} \
            --mint="1 $POLICYID.${tokenname}" \
                    --minting-script-file $scriptPath \
            --metadata-json-file ${metadatajson} \
                    --invalid-hereafter $(( ${currentSlot} + 10000)) \
                    --out-file tx.raw >> $log


echo 'amount to send user minusz fee:' $amountToSendUser
echo "Fee:"$fee

echo "NFT küldés aláírás" >> $log
                cardano-cli transaction sign \
                  --signing-key-file $paymentSignKeyPath \
               --signing-key-file $policySignKeyPath \
                  --tx-body-file tx.raw \
                  --out-file tx.signed \
                  --mainnet >> $log
echo "NFT küldés submit" >> $log
              cardano-cli transaction submit --tx-file tx.signed --mainnet >> $log
              
              
 
echo "============= mintelés vége =============" 
echo
            fi
            rm tx.*
        echo "====bejegyzés vége====" >> $log
        fi
     done < balance.out

  wait
done

I hope it help, cheers!

2

You may be interested in this MIT licensed Cardano NFT vending machine bash script available on GitHub. It hasn't been updated in 6 months, but you can fork it from the ftpmorph repo and audit to see if it does what you need.

2

We open-sourced one of these on GitHub here: https://github.com/thaddeusdiamond/cardano-nft-vending-machine

It's written in Python but requires no cardano-node (only cardano-cli and a Blockfrost key). There's also a sample script in main.py to show how to use it (or just invoke that script from CLI). Our PFP mint was done on my Macbook Pro. Hopefully that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.