Cardano Submit API (CoinCashew & CNTools Users)

NOTE

This guide works for both Coincashew and CNTool users. CNTool users should, however, skip the INSTALLING CARDANO-SUBMIT-API section and go straight to OPERATING tx-api.service USING SYSTEMD since cardano-submit-api is already installed (should be the same location file paths for both).

Feel free to change any of the file paths to suite your needs.

INSTALLING CARDANO-SUBMIT-API

Navigate to /home/user/git/cardano-node where you downloaded cardano-node and cardano-cli previously and there you will install cardano-submit-api with the following:

(taken directly from IOG github: https://github.com/input-output-hk/cardano-node/tree/56336a031c1540340c523f5a45ae8ba4b2c07cde/cardano-submit-api)

cabal install cardano-submit-api --overwrite-policy=always

Before we write the scripts/service files, we will need to locate cardano-submit-api and tx-submit-mainnet-config.yaml. You can use which cardano-submit-api to ensure the file path.

  • cardano-submit-api should be located in /home/<user_name>/.cabal/bin/

  • tx-submit-mainnet-config.yaml should be located in /home/<user_name>/git/cardano-node/cardano-submit-api/config/

OPERATING tx-api.service USING SYSTEMD

(All credit to PANL Stake Pool for writing this code!! Source: https://panl-stake-pool.gitbook.io/grafana-monitoring-setup-for-cardano-stake-pool/tx-submit-api)

Noting the above filepaths, we first create the startup script tx-api.sh. Be sure to replace instances of /path/to/ and <user_name> with appropriate values:

sudo mkdir -m777 /opt/startup-scripts
cat <<'ENDFILE' >> /opt/startup-scripts/tx-api.sh
/path/to/cardano-submit-api --config /path/to/cardano-submit-api/tx-submit-mainnet-config.yaml --socket-path /path/to/node.socket --listen-address 0.0.0.0 --port 8090 --mainnet
ENDFILE
  • /path/to/cardano-submit-api should be /home/<user_name>/.cabal/bin/cardano-submit-api

  • /path/to/cardano-submit-api/tx-submit-mainnet-config.yaml should be /home/<user_name>/git/cardano-node/cardano-submit-api/config/

  • /path/to/node.socket should be /home/<user_name>/cardano-my-node/db/socket

Next, make the script executable:

chmod +x /opt/startup-scripts/tx-api.sh

Next, we will write the tx-api.service unit configuration file (i.e., 'service' file), which will be run by systemd. Be sure to replace instances of /path/to/ and <user_name> with appropriate values:

cat <<'ENDFILE' >> /tmp/tx-api.service
[Unit]
Description=Cardano TX Submit API
After=network-online.target

[Service]
Type=simple
Restart=on-failure
RestartSec=10
User=<user_name>
WorkingDirectory=/path/to/cardano-submit-api/
ExecStart=/bin/bash -l -c "exec /opt/startup-scripts/tx-api.sh"
SuccessExitStatus=143
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=tx-api
TimeoutStopSec=2
KillMode=mixed

[Install]
WantedBy=multi-user.target
ENDFILE
  • /path/to/cardano-submit-api/ should be /home/<user_name>/git/cardano-node/cardano-submit-api/

  • <user_name> is the username under your home directory that you log into when you login into your node

Move tx-api.service to /etc/systemd/system/ so it can operated via systemd:

sudo mv /tmp/tx-api.service /etc/systemd/system/

Lastly, we enable the service to run at start and turn it on:

sudo systemctl enable tx-api.service
sudo systemctl start tx-api.service

You can ensure that tx-api.service is active by checking its status:

sudo systemctl status tx-api.service

That's all! Your url will be http://<ip-address>:8090/api/submit/tx.

TROUBLESHOOTING

If you have any issues, first check the service logs by running the following:

journalctl --unit=tx-api --follow

Note the error, make adjustments, then be sure to reload the daemon and restart the service with the following:

sudo systemctl daemon-reload
sudo systemctl reload-or-restart tx-api.service

If you need to check or edit the script or service files, you can do so with the following commands:

sudo nano /etc/systemd/system/tx-api.service
sudo nano/opt/startup-scripts/tx-api.sh 

COMMON ERRORS

1) Make sure to use http and not https if you use your ip address!

2) If for some reason you can't locate the tx-submit-mainnet-config.yaml file, you can install it with the following:

wget https://raw.githubusercontent.com/input-output-hk/cardano-node/master/cardano-submit-api/config/tx-submit-mainnet-config.yaml

3) If you start or reload tx-api.service and receive error codes 126 or 127, check the following:

  • Exit code 126 is printed when the server cannot execute the script. First, go to /opt/startup-scripts/ and make sure that the script is executable with the following:

if [[ -x "tx-api.sh" ]]
then
    echo "File 'tx-api.sh' is executable"
else
    echo "File 'tx-api.sh' is not executable or found"
fi
  • If tx-api.sh is not executable, make sure to make it executable by rerunning:

chmod +x /opt/startup-scripts/tx-api.sh
  • Another issue I ran into was to make sure that the script is written correctly. Double check the script using the following:

sudo nano /opt/startup-scripts/tx-api.sh
  • Make sure nothing looks off. Check spacing, spelling, make sure the path is to cardano-my-node located in /home/<user_name>/.cabal/bin/cardano-submit-api and NOT the directory that you downloaded under /home/<user_name>/git/cardano-node!

  • Exit code 127 is printed when the server cannot find the script. Double check that script is located in /opt/startup-scripts/

Last updated