Skip to content

Instantly share code, notes, and snippets.

@nullun
Last active September 27, 2022 14:08
Show Gist options
  • Save nullun/682a22f071ba99730d8f8265c21e3b25 to your computer and use it in GitHub Desktop.
Save nullun/682a22f071ba99730d8f8265c21e3b25 to your computer and use it in GitHub Desktop.
Demo: Fund Account, OptIn NFT, Send NFT in a single round
#!/usr/bin/env bash
set -e -u -x -o pipefail
SB=~/sandbox/sandbox
GOAL="${SB} goal"
# Use prefunded account
ACCT1=$(${GOAL} account list \
| grep '\[online\]' \
| awk '{print $3}' \
| head -n 1 \
| tail -n 1 \
| tr -d '\r')
# Create NFT
NFT_ID=$(${GOAL} asset create \
--creator ${ACCT1} \
--name "Demo NFT" \
--unitname "NFT" \
--total 1 \
--decimals 0 \
| grep 'Created asset with asset index' \
| awk '{print $6}' \
| tr -d '\r')
# Create new unfunded account
NEW_ACCT=$(${GOAL} account new \
| grep 'Created new account with address' \
| awk '{print $6}' \
| tr -d '\r')
# Construct transactions
# 0) Fund (0.1 Algo since it's new + 0.101 Algo for NFT)
${GOAL} clerk send --from ${ACCT1} --to ${NEW_ACCT} --amount 201000 -o 0_fund.txn
# 1) OptIn
${GOAL} asset send --from ${NEW_ACCT} --to ${NEW_ACCT} --assetid ${NFT_ID} --amount 0 -o 1_optin.txn
# 2) Send
${GOAL} asset send --from ${ACCT1} --to ${NEW_ACCT} --assetid ${NFT_ID} --amount 1 -o 2_send.txn
# Group transactions
${SB} copyFrom 0_fund.txn
${SB} copyFrom 1_optin.txn
${SB} copyFrom 2_send.txn
cat 0_fund.txn 1_optin.txn 2_send.txn > group.ctxn
${SB} copyTo group.ctxn
rm 0_fund.txn 1_optin.txn 2_send.txn group.ctxn
${GOAL} clerk group -i group.ctxn -o group.gtxn
# Split transactions
${GOAL} clerk split -i group.gtxn -o group.txn
# Sign transactions
${GOAL} clerk sign -i group-0.txn -o group-0.stxn
${GOAL} clerk sign -i group-1.txn -o group-1.stxn
${GOAL} clerk sign -i group-2.txn -o group-2.stxn
# Recombine transactions
${SB} copyFrom group-0.stxn
${SB} copyFrom group-1.stxn
${SB} copyFrom group-2.stxn
cat group-0.stxn group-1.stxn group-2.stxn > group.stxn
${SB} copyTo group.stxn
rm group-0.stxn group-1.stxn group-2.stxn group.stxn
# Submit atomic group in single round
${GOAL} clerk rawsend -f group.stxn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment