I created this Node.js script to automatically pet my Aavegotchis every 12 hours. It works by querying the blockchain every 15 minutes and petting any gotchis that are ready.
The script estimates gas costs based on the current market and plays nicely with EIP-1559. There is an option in the code to set a hard limit on the amount of gas to use (defaults to 0.05 MATIC).
You'll need to set up a dedicated ETH wallet with only a few bucks worth of MATIC token funded on the Polygon blockchain to cover gas fees for petting. You can use MetaMask or your favorite ERC20 wallet software to create the wallet.
DO NOT use an existing wallet that holds any assets aside from a small amount of MATIC. The private keys you provide for the script are stored in plaintext - this was not designed to be a secure solution for storing your life savings. Capiche? Okay- then let's get petting...
Aavegotchi has a setPetOperatorForAll
function that allows gotchi owners to give petting permissions to another wallet. You'll need to call this function using the wallet that owns your gotchis, specifying the address of the petting wallet. This only needs to be done once, but this script does not handle that for you.
I used louper.dev to call this function - you'll find it in the AavegotchiFacet section. Use the write button at the bottom of the section and connect your wallet to call the setPetOperatorForAll
function.
More details on this function can be found on Aavegotchi's github.
I am assuming you already have Node.js installed. The script was developed and tested with v17.4.0 & v18.
- In the root directory of the project:
npm install
- Create a .env file that looks like this:
PETTER_WALLET_ADDRESS="" # petting wallet address ie: 0x...
PETTER_WALLET_KEY="" # petting wallet private key ie: 0x...
GOTCHI_IDS="" # ids of gotchis to pet ie: id1,id2,id3
POLYGON_RPC_HOST="" # optional, if you want to use a different polygon RPC
# => defaults to https://polygon-rpc.com if ommitted)
Include the public address and private key of your dedicated petting wallet. GOTCHI_IDS
should be a comma separated list of ids. The id corresponds to the gotchis tokenId, which can also be found at the end of the url when viewing your gotchi. (ie: app.aavegotchi.com/gotchi/##### <-- the ID)
If you have a lot of Gotchis, a more effective way is to get a list of all gotchis for per account(s), eg via [fireball.gg] (https://fireball.gg/client/0x.../gotchis/owned?sort=mrs&dir=desc) (open the filter and downloads https://fireball.gg/client/0xD34DB33F/gotchis/owned?sort=mrs&dir=desc) and filter out the relevant fields via jq
cat client_gotchis_******.json | jq -j '.[].id + ","
- Run the script:
npm start
The script will run continuously until stopped, checking the status of the gotchis on the blockchain every 15 minutes. Pet transactions are only submitted if at least 12 hours has elapsed since the last time a gotchi was pet as reported by the smart contract.
If you're going to run this script in a full-time production setting, there are a few more things you may want to consider.
To run the application in the background, you can use PM2 to daemonize it. An ecosystem.config.js
file has been provided with some suggested settings. You can install PM2 globally using npm install pm2 -g
.
To start the script, use pm2 start
. To stop the script, you can use pm2 stop gotchi-petter
or use pm2 delete gotchi-petter
. You can monitor the script with pm2 logs
or, the prettier version: pm2 monit
A Containerfile is included if you want to run the script inside a container. The setup has been built and tested using Podman. Docker should work also, but hasn't been tested.
Here are some suggested commands:
Build the image (from project root):
podman build -t gotchi-petter .
Run the container
podman run -d --restart unless-stopped gotchi-petter