Challenge #3: Transactions

"Send as many transactions as you can"

Let's create a script that will send transactions periodically, so we don't have to care about sending txs manually. We will use the crontab to schedule the sender script.

Create a new script minasender.sh

cd
vim minasender.sh
#!/bin/bash
currentTime=$(date +%F-%T)
# If Mina process is active
if pgrep -x "coda" > /dev/null
then
unlocked=`echo $CODA_PRIVKEY_PASS | /usr/local/bin/coda accounts unlock -public-key B62qrYbxHUgyKMzR1tGSmZh8CF1ycU265j8mnRdcnwRH5EkxHHyH4g4 > /dev/null`
echo "$currentTime [Info] Mina process is active" >> minasender.logs
echo " [Info] sending tx.." >> minasender.logs
addr=`shuf -n 1 accounts.txt`
amount=`seq 0.010 .035 0.225 | shuf | head -n1`
fee=`seq 0.010 .035 0.225 | shuf | head -n1`
tx=`/usr/local/bin/coda client send-payment -amount $amount -receiver $addr -fee $fee -sender B62qrYbxHUgyKMzR1tGSmZh8CF1ycU265j8mnRdcnwRH5EkxHHyH4g4`
echo " fee: $fee , amount: $amount" >> minasender.logs
echo " receiver: $addr" >> minasender.logs
echo " $tx" >> minasender.logs
else
echo "$currentTime [Error] Mina process is not active" >> minasender.logs
fi

Replace B62qrYbxHUgyKMzR1tGSmZh8CF1ycU265j8mnRdcnwRH5EkxHHyH4g4 with your public key

Be careful with the limit values assigned to fee and amountvariables, you could run out of stake while you sleeping:(.

Give execution permission:

chmod +x minasender.sh

The script will create a log file minasender.logs in the same folder, where you can check and verify the transactions submitted.

Example:

Ensure that your password is correct:

echo $CODA_PRIVKEY_PASS

Create an accounts source file, where you can store the accounts you will send the MINA tokens:

vim accounts.txt
B62qrqLBXU5aPLt3jcYZbZGX39C7n1gtpueZmxFt46GEHeRofo7FF7N
B62qrYbxHUgyKMzR1tGSmZh8CF1ycU265j8mnRdcnwRH5EkxHHyH4g4
B62qobEMsZnh9brB4AWhzh3Uj7gzWqaxB17yGTYxBfYC3AGgzZ3mBFj
B62qm4suBLtLa4dJ8YqeqWXAZSdSXhd8nRavUHTPoQ3fUjA8yoStUCG
B62qojYsy6QuuRcRNxcQUwPMjSpJX36XbnGG74M21d4t1cYDJgTtWgv
B62qiqDtaaAD44KzjiyV1Vjd1YvG2edCDCgAPNSCocdsXiGnjagGq88
B62qjB7jDBnVsz6xFUX1NjneuLQQfijepfc56jkSHWkuuhhqMmdheu9
B62qmrYe5My5rF9uoF5ccEZQipMd6oTztpwZH4JFzs5Beb7umjRrdgC
B62qnBDrXCAqQ5rpuZ5svkVKP32y1WEmmt74m7wR846xDze7ovw5bgr
B62qoKBNvBaK24EcL3MGyGUNHG8kuftFUww3AC8zpW53vxmsjK1BZDb
B62qkiBSRUJ8u3ywWungL5sTVrfaar7PMYRMS4PNpEGa2ezFSXZYiit
B62qnFJzeJcjR3kJ5hXzRgGvc75dCoVuj31YncKryGcamzUsXZckofv
B62qkcmHfe4PVfFS6DPadLWxZzR2xAd2DRtmBxEVXAi4xbTCFU6WbvQ

Add a cron task

Edit the crontab:

crontab -e

Add a new line:

*/15 * * * * . $HOME/.profile; $HOME/minasender.sh

the minasender.sh script will be executed each 15 minutes. Try crontab.guru to get new examples.

Check the logs:

cat minasender.logs
2020-12-31-02:30:01 [Info] Mina process is active
[Info] sending tx..
fee: 0.046 , amount: 0.046
receiver: B62qnFJzeJcjR3kJ5hXzRgGvc75dCoVuj31YncKryGcamzUsXZckofv
Dispatched payment with ID 29oBRYxP4TVPTfRDQEZYz7obSRQnYtuyuqxcdCMNDqJyo1TnuvyVpuGnZQicbEgxcKz8p3WzRi6UvDZ6GKVcb7bg3Lm4sUQS5FRtLJqPV7ELMQvJHf946uD2Fa15K1aExEDWZtXudBsfNBsqL3NZgN9eQAXJq3so9kV7u2LaaQsJE3k5V1dJKbR2GRJqjG9QJkqeU21MThHEQze4rtrET5qkPzj7EXsMfSMNAhKgdpK82dY7TUgxFE1EFtk2wBA1Pwnjc1W9GkoLM5muFFjECCMFY4xA5F8ET6votTfowZ2EkNMf18bqADUCyPtfe6TbiC85irKngLXToQGbXwWvcypdLBu4aPVZh2ny9PW4BkkRhTD9zMvqzXcinqhMSPrEi2tygx1y9fn

Remember to call to faucet bot in Discord to get a few free MINA tokens.