Cli를 통한 원장(transaction) 작성

먼저 모든 cli setup이 끝났다고 가정합니다.
cli를 통해 transaction을 생성해보시면 이전의 설치 과정이 어떤 과정이었는지 좀 더 명확해지는 효과가 있습니다. 한번정도 시도해보시길 추천합니다.

현재의 utxo값을 query

cardano-cli query utxo \
--address $(cat payment.addr) \
--mainnet \
--mary-era

result는 아래와 같습니다.

          TxHash                                                 TxIx       Amount
--------------------------------------------------------------------------------------
bf84cc8fd2a91549403116d12afe67bee1cc00eb2813088a74dfe99999e7733d   0   5638638 lovelace

원장의 draft를 작성합니다.

cardano-cli transaction build-raw \
--tx-in bf84cc8fd2a91549403116d12afe67bee1cc00eb2813088a74dfe99999e7733d#0 \
--tx-out $(cat payment2.addr)+0 \
--tx-out $(cat payment.addr)+0 \
--invalid-hereafter 0 \
--fee 0 \
--out-file tx.draft
tx-in에는 ${TxHash}#${TxIx}값을 위와 같이 넣어줍니다.
payment.addr은 나의 지갑 주소이고, payment2.addr은 받을 지갑의 주소입니다.

fee를 계산합니다.

송금할때 사용되는 수수료가 얼마인지 계산합니다.

cardano-cli transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count 1 \
--tx-out-count 2 \
--witness-count 1 \
--byron-witness-count 0 \
--mainnet \
--protocol-params-file params.json

저는 결과로 fee가 이만큼 나왔습니다.

176413 Lovelace

지갑에 남게될 ADA를 계산합니다.

현재 ADA(이 POST 기준으로는 5638638) - fee(176413) - 보낼 ADA

저는 모두 보낼 계획이기 때문에 1000000 입니다.

(shelly-genesis.json에 “minUTxOValue”: 1000000로 설정 되어 있어 그 밑으로 남길 수는 없습니다.)

TTL 값을 SET 해줍니다.

현재 원장이 언제까지 유효한지 여부를 결정합니다.

cardano-cli query tip --mainnet
{
  "blockNo": 5456016,
  "headerHash": "3dd26f2b24de1408bab90abdec44569074a5e93cba506bea9e5517855f6ca637",
  "slotNo": 24074421
}

현재 SLOT NUMBER는 24074421입니다. 넉넉하게 +10000 정도 해줍니다.

24084421을 SET 하도록 하겠습니다.

원장을 작성합니다.

cardano-cli transaction build-raw \ --tx-in bf84cc8fd2a91549403116d12afe67bee1cc00eb2813088a74dfe99999e7733d#0 \ --tx-out {ADA를받을주소}+4462225 \ --tx-out (cat payment.addr)+1000000 \ --invalid-hereafter 24084421 \ --fee 167965 \ --out-file tx.raw

원장을 SIGNING 합니다.

payment.skey가 있는 COLD STORAGE로 가서 signing 하도록 합니다. 만약 같은 머신에서 처리했다면 거기서 진행하시면 됩니다.

cardano-cli transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--mainnet \
--out-file tx.signed

원장을 보냅니다.

cardano-cli transaction submit \
--tx-file tx.signed \
--mainnet

이제 보낸 지갑으로 가보시면 ADA가 도착한것을 알 수 있습니다.(수십초 이내)

실패할 경우 UtxoFailure에 실패한 이유가 나오게 됩니다.

FeeTooSmallUTxO

Shelley command failed: transaction submit Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (UtxoFailure (FeeTooSmallUTxO (Coin 168097) (Coin 167965)))),LedgerFailure (UtxowFailure (UtxoFailure (ValueNotConservedUTxO (Value 5638638 (fromList [])) (Value 5630190 (fromList [])))))]

OutputTooSmallUTxO

Shelley command failed: transaction submit Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (UtxoFailure (ValueNotConservedUTxO (Value 5638638 (fromList [])) (Value 5806603 (fromList []))))),LedgerFailure (UtxowFailure (UtxoFailure (OutputTooSmallUTxO [(Addr Mainnet (KeyHashObj (KeyHash "c49fe9c0852f0374a64265acd7377982647c3b0371ee6bec342ff4c7")) (StakeRefBase (KeyHashObj (KeyHash "667f9badb1fe5a2b7562e0e75bc830770b045c6a9a1cf2f849dbfc41"))),Value 0 (fromList []))])))]