How to construct cardano transaction using cardano-rosetta and cardano-addresses

I’m learning how to use cardano-rosetta and I’d like to make the send-transaction-example.ts script work with addresses that I’ve derived beforehand. The addresses have been derived using the cardano-addresses tool, which I then convert to Uint8 arrays. This is because we need to derive batches of addresses that may be used in future.

The transaction is constructed and signed, seemingly without any issue. The server log is below. However, the transaction is rejected. The API response isn’t very descriptive, I get only a 500 error, but the server log is below. The issue seems to be in this line:

[53047783:cardano.node.Mempool:Info:38002] [2021-03-30 15:55:43.90 UTC] fromList [("tx",Object (fromList [("txid",String "txid: TxId {_unTxId = \"831f0e898a7d6653149bf2f6fc6ea7b482deb04f49251a1edd612051f42617b2\"}")])),("kind",String "TraceMempoolRejectedTx"),("mempoolSize",Object (fromList [("numTxs",Number 0.0),("bytes",Number 0.0)])),("err",Object (fromList [("kind",String "InvalidWitnessesUTXOW"),("invalidWitnesses",Array [String "VKey (VerKeyEd25519DSIGN (PublicKey \"\\158\\238W\\128\\184$:E\\231\\FSa\\152I$\\EM\\b\\134\\CAN\\140\\157N\\154\\238r\\EOT\\173\\204\\172c4cr\"))"])]))]

I don’t know why the witness is invalid. could anyone help?

{"level":30,"time":1617119743744,"pid":106,"hostname":"530477839db5","reqId":1392,"msg":"[constructionCombine] Request received to sign a transaction","v":1}
{"level":30,"time":1617119743745,"pid":106,"hostname":"530477839db5","reqId":1392,"msg":"[buildTransaction] About to signed a transaction with 1 signatures","v":1}
{"level":30,"time":1617119743745,"pid":106,"hostname":"530477839db5","reqId":1392,"msg":"[getWitnessesForTransaction] Extracting witnesses from signatures","v":1}
{"level":30,"time":1617119743745,"pid":106,"hostname":"530477839db5","reqId":1392,"msg":"[getWitnessesForTransaction] 1 witnesses were extracted to sign transaction","v":1}
{"level":30,"time":1617119743745,"pid":106,"hostname":"530477839db5","reqId":1392,"msg":"[buildTransaction] Instantiating transaction body from unsigned transaction bytes","v":1}
{"level":30,"time":1617119743745,"pid":106,"hostname":"530477839db5","reqId":1392,"msg":"[buildTransaction] Creating transaction using transaction body and extracted witnesses","v":1}
{"level":30,"time":1617119743745,"pid":106,"hostname":"530477839db5","reqId":1392,"signedTransaction":"83a400818258204bc397faa17b5f7972cfd6acf2729eb950b5756c8ea2f704ec8ef11d8a3718fb000181825839000c6d3e4ad14b5ac97656fe56cae3d46e4474af25f6f4d25268b8a168474ac229ab36f3ebb93da86e068f35f5a64bcc0e4ed40cc295fca2df1a389fd980021a02faf080031a015b291ba100818258209eee5780b8243a45e71c61984924190886188c9d4e9aee7204adccac633463725840b2e842c390b4142c46e9d08dd5fc366cb37fc960ab48bdeb083134d79858928775e8304f8c25a5cd5d531f9fd7579188fdb659a27e8f418c12a6aada0fda7600f6","msg":"[constructionCombine] About to return signed transaction","v":1}
{"level":30,"time":1617119743747,"pid":106,"hostname":"530477839db5","reqId":1392,"res":{"statusCode":200},"responseTime":3.006010055541992,"msg":"request completed","v":1}
{"level":30,"time":1617119743887,"pid":106,"hostname":"530477839db5","reqId":1393,"req":{"method":"POST","url":"/construction/submit","hostname":"35.214.159.230:8080","remoteAddress":"84.247.50.48","remotePort":55196},"msg":"incoming request","v":1}
{"level":30,"time":1617119743888,"pid":106,"hostname":"530477839db5","reqId":1393,"msg":"[constructionSubmit] About to submit 83a400818258204bc397faa17b5f7972cfd6acf2729eb950b5756c8ea2f704ec8ef11d8a3718fb000181825839000c6d3e4ad14b5ac97656fe56cae3d46e4474af25f6f4d25268b8a168474ac229ab36f3ebb93da86e068f35f5a64bcc0e4ed40cc295fca2df1a389fd980021a02faf080031a015b291ba100818258209eee5780b8243a45e71c61984924190886188c9d4e9aee7204adccac633463725840b2e842c390b4142c46e9d08dd5fc366cb37fc960ab48bdeb083134d79858928775e8304f8c25a5cd5d531f9fd7579188fdb659a27e8f418c12a6aada0fda7600f6","v":1}
[53047783:cardano.node.Mempool:Info:38002] [2021-03-30 15:55:43.90 UTC] fromList [("tx",Object (fromList [("txid",String "txid: TxId {_unTxId = \"831f0e898a7d6653149bf2f6fc6ea7b482deb04f49251a1edd612051f42617b2\"}")])),("kind",String "TraceMempoolRejectedTx"),("mempoolSize",Object (fromList [("numTxs",Number 0.0),("bytes",Number 0.0)])),("err",Object (fromList [("kind",String "InvalidWitnessesUTXOW"),("invalidWitnesses",Array [String "VKey (VerKeyEd25519DSIGN (PublicKey \"\\158\\238W\\128\\184$:E\\231\\FSa\\152I$\\EM\\b\\134\\CAN\\140\\157N\\154\\238r\\EOT\\173\\204\\172c4cr\"))"])]))]
{"level":50,"time":1617119743909,"pid":106,"hostname":"530477839db5","reqId":1393,"shortMessage":"Command failed with exit code 1: /usr/local/bin/cardano-cli transaction submit --tx-file /tmp/6edd9e54-ea83-420c-b5b8-c0c2ea722dc6 --testnet-magic 1097911063","command":"/usr/local/bin/cardano-cli transaction submit --tx-file /tmp/6edd9e54-ea83-420c-b5b8-c0c2ea722dc6 --testnet-magic 1097911063","exitCode":1,"stdout":"","stderr":"Shelley command failed: transaction submit  Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (InvalidWitnessesUTXOW [VKey (VerKeyEd25519DSIGN (PublicKey \"\\158\\238W\\128\\184$:E\\231\\FSa\\152I$\\EM\\b\\134\\CAN\\140\\157N\\154\\238r\\EOT\\173\\204\\172c4cr\"))]))]","failed":true,"timedOut":false,"isCanceled":false,"killed":false,"msg":"[submitTransaction] Command failed","stack":"Error: Command failed with exit code 1: /usr/local/bin/cardano-cli transaction submit --tx-file /tmp/6edd9e54-ea83-420c-b5b8-c0c2ea722dc6 --testnet-magic 1097911063\nShelley command failed: transaction submit  Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (InvalidWitnessesUTXOW [VKey (VerKeyEd25519DSIGN (PublicKey \"\\158\\238W\\128\\184$:E\\231\\FSa\\152I$\\EM\\b\\134\\CAN\\140\\157N\\154\\238r\\EOT\\173\\204\\172c4cr\"))]))]\n    at makeError (/cardano-rosetta-server/node_modules/execa/lib/error.js:59:11)\n    at handlePromise (/cardano-rosetta-server/node_modules/execa/index.js:114:26)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (internal/process/task_queues.js:93:5)","type":"Error","v":1}
{"level":50,"time":1617119743910,"pid":106,"hostname":"530477839db5","reqId":1393,"msg":"Shelley command failed: transaction submit  Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (InvalidWitnessesUTXOW [VKey (VerKeyEd25519DSIGN (PublicKey \"\\158\\238W\\128\\184$:E\\231\\FSa\\152I$\\EM\\b\\134\\CAN\\140\\157N\\154\\238r\\EOT\\173\\204\\172c4cr\"))]))]","stack":"Error: Shelley command failed: transaction submit  Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (InvalidWitnessesUTXOW [VKey (VerKeyEd25519DSIGN (PublicKey \"\\158\\238W\\128\\184$:E\\231\\FSa\\152I$\\EM\\b\\134\\CAN\\140\\157N\\154\\238r\\EOT\\173\\204\\172c4cr\"))]))]\n    at Object.<anonymous> (/cardano-rosetta-server/dist/src/server/utils/cardano/cli/cardanonode-cli.js:60:31)\n    at Generator.throw (<anonymous>)\n    at rejected (/cardano-rosetta-server/dist/src/server/utils/cardano/cli/cardanonode-cli.js:6:65)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (internal/process/task_queues.js:93:5)","type":"Error","v":1}
{"level":50,"time":1617119743910,"pid":106,"hostname":"530477839db5","reqId":1393,"code":5006,"retriable":true,"details":{"message":"Shelley command failed: transaction submit  Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (InvalidWitnessesUTXOW [VKey (VerKeyEd25519DSIGN (PublicKey \"\\158\\238W\\128\\184$:E\\231\\FSa\\152I$\\EM\\b\\134\\CAN\\140\\157N\\154\\238r\\EOT\\173\\204\\172c4cr\"))]))]"},"msg":"[errorHandler] An error ocurred and will be sent as response","stack":"Error: Error when sending the transaction\n    at Object.exports.buildApiError (/cardano-rosetta-server/dist/src/server/utils/errors.js:86:56)\n    at Object.sendTransactionError (/cardano-rosetta-server/dist/src/server/utils/errors.js:108:51)\n    at /cardano-rosetta-server/dist/src/server/controllers/construction-controller.js:170:46\n    at Generator.throw (<anonymous>)\n    at rejected (/cardano-rosetta-server/dist/src/server/controllers/construction-controller.js:6:65)","type":"Error","v":1}
{"level":30,"time":1617119743911,"pid":106,"hostname":"530477839db5","reqId":1393,"res":{"statusCode":500},"responseTime":23.158724784851074,"msg":"request completed","v":1}

just curious why you started to use this tool?

cos I have a bunch of different blockchain nodes to interact with, and using a single API to do it would be convenient.

1 Like

just checked the script and there is a secretKey cost and then then the signing and verification keys generated for that by the script - so I dont know why is not ok… are you using that const key?

If I use the secret key that is hardcoded into the example, it works as expected. When I derive my own key pair I get this error about the invalid witness (the rest of the script runs ok).

I thought perhaps I was deriving the keys incorrectly, and used cardano-address key inspect … on the hardcoded key and the public key the script derives from it, but this led to an error in the cardano-address tool (send-transaction-example generates addresses that cardano-addresses can't inspect · Issue #331 · input-output-hk/cardano-rosetta · GitHub).

Thanks for checking the script. As far as I can tell I’m deriving keys and addresses correctly, and can’t find any evidence to the contrary (except the invalid witness, which i cant find any info about).

Can you point me to any documentation about the witnesses/signing? or suggest a better way to derive batches of addresses and then use them with cardano-rosetta?

do you have a cardano-node running?

Yes.

I can construct, sign and send transactions without problems if I used the examples hardcoded private key. I cant do it when I use keys/addresses that I’ve derived using the cardano-address tool.

so could you do it without cardano-rosetta? use the generated keys with cardano-cli
https://docs.cardano.org/projects/cardano-node/en/latest/stake-pool-operations/simple_transaction.html

–mary-era flag is missing from several command - but then at least you can verify that the addresses are ok

I think I can be confident that the keys are not ok, because the keys are the only thing that is changed between using the send-transaction-example as provided, and modifying it for my needs.

But I do not know how to generate keys/addresses without using cardano-address. (The addresses generated via cardano-address are valid, as I can send test ada from the faucet to these addresses).

yes, so you need to verify that the verification key is ok - by sending ADA. I am sure that cardano-address can generate valid keys…
but you can generate keys with cardano-cli as well - but those wont be derived from recovery phase.
https://docs.cardano.org/projects/cardano-node/en/latest/stake-pool-operations/keys_and_addresses.html

ok… but is this not what the cardano-address key inspect.. command does, though?

This is the output of the key inspect command on a key pair, which led me to believe the keys are valid:

PRIVATE addr.xsk
addr_xsk10qhc23nf2tczkvydvckxkj6jmmv8xvqtxe7fnxa38e90ptec6a29j0wd5ka2lxqxvcl0h8kq4eu8fgrlwztdg2c074hek2ts8vg3h5pkc2sxazf9gruktf848k9msfscfs6nd37ertfhfhkkddjgptmk5uqerzv3
{
    "chain_code": "36c2a06e892540f965a4f53d8bb826184c3536c7d91ad374ded66b6480af76a7",
    "key_type": "private",
    "extended_key": "782f85466952f02b308d662c6b4b52ded873300b367c999bb13e4af0af38d754593dcda5baaf9806663efb9ec0ae7874a07f7096d42b0ff56f9b29703b111bd0"
}
PUBLIC addr.xvk
addr_xvk1kf4lh8uz9e37uc2qt85emnruplyrg6el4rlqg7r9g5c4cx56ajynds4qd6yj2s8evkj020vthqnpsnp4xmrajxknwn0dv6myszhhdfcyrkhg4
{
    "chain_code": "36c2a06e892540f965a4f53d8bb826184c3536c7d91ad374ded66b6480af76a7",
    "key_type": "public",
    "extended_key": "b26bfb9f822e63ee614059e99dcc7c0fc8346b3fa8fe04786545315c1a9aec89"
}

yes - so if you would make a single transaction with cardano-cli then you would verify that the keys are correct…