Build a Complex Transaction
Simple Transactions
Sending a transaction using the Flow CLI can simply be achieved by using the send command documented here.
Complex Transactions
If you would like to build more complex transactions the Flow CLI provides commands to build, sign and send transactions allowing you to specify different authorizers, signers and proposers.
The process of sending a complex transactions includes three steps:
Read more about each command flags and arguments in the above links.
Examples
We will describe common examples for complex transactions. All examples are using an example configuration.
Single payer, proposer and authorizer
The simplest Flow transaction declares a single account as the proposer, payer and authorizer.
Build the transaction:
_10> flow transactions build tx.cdc _10 --proposer alice _10 --payer alice _10 --authorizer alice _10 --filter payload --save tx1
Sign the transaction:
_10> flow transactions sign tx1 --signer alice _10 --filter payload --save tx2
Submit the signed transaction:
_10> flow transactions send-signed tx2
Transaction content (tx.cdc
):
_10transaction {_10 prepare(signer: &Account) {}_10 execute { ... }_10}
Single payer and proposer, multiple authorizers
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.
Build the transaction:
_10> flow transactions build tx.cdc _10 --proposer alice_10 --payer alice_10 --authorizer bob_10 --authorizer charlie _10 --filter payload --save tx1
Sign the transaction with authorizers:
_10> flow transactions sign tx1 --signer bob_10 --filter payload --save tx2
_10> flow transactions sign tx2 --signer charlie_10 --filter payload --save tx3
Sign the transaction with payer:
_10> flow transactions sign tx3 --signer alice_10 --filter payload --save tx4
Submit the signed transaction:
_10> flow transactions send-signed tx4
Transaction content (tx.cdc
):
_10transaction {_10 prepare(bob: &Account, charlie: &Account) {}_10 execute { ... }_10}
Different payer, proposer and authorizer
A transaction that declares different payer, proposer and authorizer each signing separately. Please note that the order of signing is important, and the payer must sign last.
Build the transaction:
_10> flow transactions build tx.cdc _10 --proposer alice _10 --payer bob _10 --authorizer charlie _10 --filter payload --save tx1
Sign the transaction with proposer:
_10> flow transactions sign tx1 --signer alice _10 --filter payload --save tx2
Sign the transaction with authorizer:
_10> flow transactions sign tx2 --signer charlie _10 --filter payload --save tx3
Sign the transaction with payer:
_10> flow transactions sign tx3 --signer bob _10 --filter payload --save tx4
Submit the signed transaction:
_10> flow transactions send-signed tx4
Transaction content (tx.cdc
):
_10transaction {_10 prepare(charlie: &Account) {}_10 execute { ... }_10}
Single payer, proposer and authorizer but multiple keys
A transaction that declares same payer, proposer and authorizer but the signer account has two keys with half weight, required to sign with both.
Build the transaction:
_10> flow transactions build tx.cdc _10 --proposer dylan1 _10 --payer dylan1_10 --authorizer dylan1 _10 --filter payload --save tx1
Sign the transaction with the first key:
_10> flow transactions sign tx1 --signer dylan1 _10 --filter payload --save tx2
Sign the transaction with the second key:
_10> flow transactions sign tx2 --signer dylan2 _10 --filter payload --save tx3
Submit the signed transaction:
_10> flow transactions send-signed tx3
Transaction content (tx.cdc
):
_10transaction {_10 prepare(signer: &Account) {}_10 execute { ... }_10}
Configuration
This is an example configuration using mock values:
_26{_26 ... _26 "accounts": {_26 "alice": {_26 "address": "0x1",_26 "key": "111...111"_26 },_26 "bob": {_26 "address": "0x2",_26 "key": "222...222"_26 },_26 "charlie": {_26 "address": "0x3",_26 "key": "333...333"_26 },_26 "dylan1": {_26 "address": "0x4",_26 "key": "444...444"_26 },_26 "dylan2": {_26 "address": "0x4",_26 "key": "555...555"_26 }_26 }_26 ..._26}