I’m using the Cardano-Wallet server to send tADA and it works just fine when pasting directly from the command prompt.
curl --request POST \
--url http://localhost:1337/v2/wallets/5076b34c6949dbd150eb9c39039037543946bdce/transactions \
--header 'Content-Type: application/json' \
--data '{
"passphrase": "test123456",
"payments": [
{
"address": "addr_test1qzyfnjk3zmgzmvnnvnpeguv6se2ptjj3w3uuh30llqe5xdtzdduxxvke8rekwukyn0qt9g5pahasrnrdmv7nr86x537qxdgza0",
"amount": {
"quantity": 250000000,
"unit": "lovelace"
}
}
]
}'
Now i want to put it inside a script so i can issue this command at the prompt:
pay.sh from_walletID to_wallet_address tADA_amount
Here’s the content of pay.sh:
URL="http://localhost:1338/v2/wallets/$1/transactions"
to_address="$2"
tADA_amount=$3
curl --request POST \
--url "$URL" \
--header 'Content-Type: application/json' \
--data '{
"passphrase": "test123456",
"payments": [
{
"address": "$to_address",
"amount": {
"quantity": $tADA_amount,
"unit": "lovelace"
}
}
]
}'
When I issue the script i get this error:
{"message":"I couldn't understand the content of your message. If your message is intended to be in JSON format, please check that the JSON is valid.","code":"bad_request"}
So I tried manually replacing variables $to_address
and $tADA_amount
with real values and the script works fine. It looks like the $tADA_amount
is being read as string when it’s expected to be a number while the $to_address
is already a string but still gets an error.
So how do I correctly format the variables $to_address
and $tADA_amount
?