|
| 1 | +--- |
| 2 | +title: Send Complex Transaction with the Flow CLI |
| 3 | +sidebar_title: Build a Complex Transaction |
| 4 | +description: How to build and send a complex Flow transaction from the command line |
| 5 | +--- |
| 6 | + |
| 7 | +The Flow CLI provides commands to build, sign and send transactions allowing you to specify different authorizers, signers and proposers. |
| 8 | + |
| 9 | +The process of sending a complex transactions includes three steps: |
| 10 | +1. [build a transaction](/build-transactions/) |
| 11 | +2. [sign the built transaction](/sign-transaction/) |
| 12 | +3. [send signed transaction](/send-signed-transactions/) |
| 13 | + |
| 14 | +Read more about each command flags and arguments in the above links. |
| 15 | + |
| 16 | +## Examples |
| 17 | +We will describe common examples for complex transactions. All examples are using an [example configuration](#configuration). |
| 18 | + |
| 19 | +### Single payer, proposer and authorizer |
| 20 | +The simplest Flow transaction declares a single account as the proposer, payer and authorizer. |
| 21 | + |
| 22 | +Build the transaction: |
| 23 | +```shell |
| 24 | +> flow transactions build tx.cdc |
| 25 | + --proposer alice |
| 26 | + --payer alice |
| 27 | + --authorizer alice |
| 28 | + --filter payload --save tx1 |
| 29 | +``` |
| 30 | +Sign the transaction: |
| 31 | +```shell |
| 32 | +> flow transactions sign tx1 --signer alice |
| 33 | + --filter payload --save tx2 |
| 34 | +``` |
| 35 | +Submit the signed transaction: |
| 36 | +```shell |
| 37 | +> flow transactions send-signed tx2 |
| 38 | +``` |
| 39 | +Transaction content (`tx.cdc`): |
| 40 | +``` |
| 41 | +transaction { |
| 42 | + preapre(signer: AuthAccount) {} |
| 43 | + execute { ... } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +### Single payer and proposer, multiple authorizers |
| 48 | +A transaction that declares same payer and proposer but multiple authorizers each required to sign the transaction. Please note that the order of signing is important, and [the payer must sign last](https://docs.onflow.org/concepts/transaction-signing/#payer-signs-last). |
| 49 | + |
| 50 | +Build the transaction: |
| 51 | +```shell |
| 52 | +> flow transactions build tx.cdc |
| 53 | + --proposer alice |
| 54 | + --payer alice |
| 55 | + --authorizer bob |
| 56 | + --authorizer charlie |
| 57 | + --filter payload --save tx1 |
| 58 | +``` |
| 59 | +Sign the transaction with authorizers: |
| 60 | +```shell |
| 61 | +> flow transactions sign tx1 --signer bob |
| 62 | + --filter payload --save tx2 |
| 63 | +``` |
| 64 | +```shell |
| 65 | +> flow transactions sign tx2 --signer charlie |
| 66 | + --filter payload --save tx3 |
| 67 | +``` |
| 68 | +Sign the transaction with payer: |
| 69 | +```shell |
| 70 | +> flow transactions sign tx3 --signer alice |
| 71 | + --filter payload --save tx4 |
| 72 | +``` |
| 73 | +Submit the signed transaction: |
| 74 | +```shell |
| 75 | +> flow transactions send-signed tx4 |
| 76 | +``` |
| 77 | +Transaction content (`tx.cdc`): |
| 78 | +``` |
| 79 | +transaction { |
| 80 | + preapre(bob: AuthAccount, charlie: AuthAccount) {} |
| 81 | + execute { ... } |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +### Different payer, proposer and authorizer |
| 86 | +A transaction that declares different payer, proposer and authorizer each signing separately. |
| 87 | +Please note that the order of signing is important, and [the payer must sign last](https://docs.onflow.org/concepts/transaction-signing/#payer-signs-last). |
| 88 | + |
| 89 | +Build the transaction: |
| 90 | +```shell |
| 91 | +> flow transactions build tx.cdc |
| 92 | + --proposer alice |
| 93 | + --payer bob |
| 94 | + --authorizer charlie |
| 95 | + --filter payload --save tx1 |
| 96 | +``` |
| 97 | +Sign the transaction with proposer: |
| 98 | +```shell |
| 99 | +> flow transactions sign tx1 --signer alice |
| 100 | + --filter payload --save tx2 |
| 101 | +``` |
| 102 | +Sign the transaction with authorizer: |
| 103 | +```shell |
| 104 | +> flow transactions sign tx2 --signer charlie |
| 105 | + --filter payload --save tx3 |
| 106 | +``` |
| 107 | +Sign the transaction with payer: |
| 108 | +```shell |
| 109 | +> flow transactions sign tx3 --signer bob |
| 110 | + --filter payload --save tx4 |
| 111 | +``` |
| 112 | +Submit the signed transaction: |
| 113 | +```shell |
| 114 | +> flow transactions send-signed tx4 |
| 115 | +``` |
| 116 | +Transaction content (`tx.cdc`): |
| 117 | +``` |
| 118 | +transaction { |
| 119 | + preapre(charlie: AuthAccount) {} |
| 120 | + execute { ... } |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +### Single payer, proposer and authorizer but multiple keys |
| 125 | +A transaction that declares same payer, proposer and authorizer but the signer account has two keys with half weight, required to sign with both. |
| 126 | + |
| 127 | + |
| 128 | +Build the transaction: |
| 129 | +```shell |
| 130 | +> flow transactions build tx.cdc |
| 131 | + --proposer dylan1 |
| 132 | + --payer dylan1 |
| 133 | + --authorizer dylan1 |
| 134 | + --filter payload --save tx1 |
| 135 | +``` |
| 136 | +Sign the transaction with the first key: |
| 137 | +```shell |
| 138 | +> flow transactions sign tx1 --signer dylan1 |
| 139 | + --filter payload --save tx2 |
| 140 | +``` |
| 141 | +Sign the transaction with the second key: |
| 142 | +```shell |
| 143 | +> flow transactions sign tx2 --signer dylan2 |
| 144 | + --filter payload --save tx3 |
| 145 | +``` |
| 146 | +Submit the signed transaction: |
| 147 | +```shell |
| 148 | +> flow transactions send-signed tx3 |
| 149 | +``` |
| 150 | +Transaction content (`tx.cdc`): |
| 151 | +``` |
| 152 | +transaction { |
| 153 | + preapre(signer: AuthAccount) {} |
| 154 | + execute { ... } |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +### Configuration |
| 159 | +This is an example configuration using mock values: |
| 160 | +```json |
| 161 | +{ |
| 162 | + ... |
| 163 | + "accounts": { |
| 164 | + "alice": { |
| 165 | + "address": "0x1", |
| 166 | + "key": "111...111" |
| 167 | + }, |
| 168 | + "bob": { |
| 169 | + "address": "0x2", |
| 170 | + "key": "222...222" |
| 171 | + }, |
| 172 | + "charlie": { |
| 173 | + "address": "0x3", |
| 174 | + "key": "333...333" |
| 175 | + }, |
| 176 | + "dylan1": { |
| 177 | + "address": "0x4", |
| 178 | + "key": "444...444" |
| 179 | + }, |
| 180 | + "dylan2": { |
| 181 | + "address": "0x4", |
| 182 | + "key": "555...555" |
| 183 | + } |
| 184 | + } |
| 185 | + ... |
| 186 | +} |
| 187 | +``` |
0 commit comments