-
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connect-explorer): document cardanoComposeTransaction
- Loading branch information
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
packages/connect-explorer/src/pages/methods/cardano/cardanoComposeTransaction.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { CardanoComposeTransactionParams } from '@trezor/connect/src/types/api/cardanoComposeTransaction'; | ||
|
||
import { ParamsTable } from '../../../components/ParamsTable'; | ||
import { CommonParamsLink } from '../../../components/CommonParamsLink'; | ||
import { ApiPlayground } from '../../../components/ApiPlayground'; | ||
|
||
<ApiPlayground | ||
options={[ | ||
{ | ||
title: 'Advanced schema', | ||
method: 'cardanoComposeTransaction', | ||
schema: CardanoComposeTransactionParams, | ||
}, | ||
]} | ||
/> | ||
|
||
export const paramDescriptions = {}; | ||
|
||
## Cardano: Compose transaction | ||
|
||
Composes a transaction from the given account information and outputs. | ||
|
||
```javascript | ||
const result = await TrezorConnect.cardanoComposeTransaction(params); | ||
``` | ||
|
||
### Params | ||
|
||
<CommonParamsLink /> | ||
|
||
<ParamsTable schema={CardanoComposeTransactionParams} descriptions={paramDescriptions} /> | ||
|
||
### Examples | ||
|
||
```javascript | ||
// Get account info | ||
const accountInfo = await TrezorConnect.getAccountInfo({ | ||
path: "m/1852'/1815'/0'/0/0", | ||
coin: 'cardano', | ||
details: 'txs', | ||
}); | ||
const account = accountInfo.payload; | ||
|
||
// Find an unused change address | ||
const changeAddress = account.addresses.change.find(a => a.transfers === 0); | ||
|
||
TrezorConnect.cardanoComposeTransaction({ | ||
account: { | ||
descriptor: account.descriptor, | ||
addresses: account.addresses, | ||
utxo: account.utxo, | ||
}, | ||
changeAddress, | ||
addressParameters: { | ||
addressType: CardanoAddressType.BASE, | ||
path: changeAddress.path, | ||
}, | ||
outputs: [ | ||
{ | ||
format: CardanoTxOutputSerializationFormat.ARRAY_LEGACY, | ||
address: | ||
'addr1q84sh2j72ux0l03fxndjnhctdg7hcppsaejafsa84vh7lwgmcs5wgus8qt4atk45lvt4xfxpjtwfhdmvchdf2m3u3hlsd5tq5r', | ||
amount: '1', | ||
}, | ||
], | ||
feeLevels: [{ feePerUnit: '1' }, { feePerUnit: '5' }, { feePerUnit: '30' }], | ||
testnet: false, | ||
}); | ||
``` | ||
|
||
### Result | ||
|
||
[PrecomposedTransactionCardano[] type](https://github.com/trezor/trezor-suite/blob/develop/packages/connect/src/types/api/cardanoComposeTransaction.ts#L41) | ||
|
||
PrecomposedTransactionFinalCardano | ||
|
||
```javascript | ||
{ | ||
success: true, | ||
payload: { | ||
type: 'final'; | ||
max?: string; | ||
totalSpent: string; // all the outputs, no fee, no change | ||
fee: string; | ||
feePerByte: string; | ||
bytes: number; | ||
deposit?: string; | ||
ttl?: number; | ||
inputs: CardanoInput[]; | ||
outputs: CardanoOutput[]; | ||
unsignedTx: { | ||
body: string; | ||
hash: string; | ||
}; | ||
} | ||
} | ||
``` | ||
|
||
PrecomposedTransactionNonFinalCardano | ||
|
||
```javascript | ||
{ | ||
success: true, | ||
payload: { | ||
type: 'nonfinal'; | ||
max?: string; | ||
totalSpent: string; // all the outputs, no fee, no change | ||
fee: string; | ||
feePerByte: string; | ||
bytes: number; | ||
deposit?: string; | ||
} | ||
} | ||
``` | ||
|
||
Error | ||
|
||
```javascript | ||
{ | ||
success: false, | ||
payload: { | ||
error: string // error message | ||
} | ||
} | ||
``` |