Parties
Parties are one of the foundational concepts in Tx3. They represent the various actors that interact with your blockchain protocol, such as users, contracts, or services.
Why Parties Matter
In UTxO blockchains like Cardano, addresses control UTxOs. Rather than hardcoding addresses, Tx3 uses the concept of parties to:
- Abstract implementation details - Separating roles from specific addresses
- Improve readability - Making transactions easier to understand
- Enable configuration - Allowing the same protocol to work with different addresses
- Support parameterization - Letting transactions work with dynamic parties
Party Definition Syntax
The basic syntax for defining a party is:
party {Name};
Where Name
is an alphanumeric identifier (starting with a letter) that represents this party throughout your protocol.
Simple Party Examples
// Basic parties representing different rolesparty User; // End user of the protocolparty Treasury; // Treasury that holds protocol fundsparty Oracle; // Data provider
Usage
Parties define the “who” in transactions - who provides inputs and who receives outputs.
Input Sources
Parties specify who controls the UTxOs that will be consumed:
party User;// User is providing Ada as inputtx deposit(amount: Int) { // UTxO controlled by the User party input user_tokens { from: User, min_amount: Ada(amount) + fees, }
// Rest of transaction...}
Output Recipients
Parties specify who will receive newly created UTxOs:
party Treasury;// Treasury is receiving protocol feesponer adentro de una txtx fund() { // Rest of transaction... output { to: Treasury, // UTxO will be sent to Treasury's address (which can be a script address as well!) amount: Ada(fee_amount), }}
Complex Party Relationships
Real-world protocols typically involve multiple parties with different roles:
party EscrowContract;party Buyer;party EscrowProvider;
tx escrow_payment( seller_item_id: Bytes, price: Int, escrow_fee: Int,) { input payment { from: Buyer, min_amount: Ada(price + escrow_fee) + fees, }
output locked_payment { to: EscrowContract, amount: Ada(price), datum: EscrowState { buyer: Buyer, seller: Seller, item_id: seller_item_id, amount: price, } }
output { to: EscrowProvider, amount: Ada(escrow_fee), }
output { to: Buyer, amount: payment - escrow_fee - Ada(price) - fees, }}
Party Properties and Methods
Parties have properties and methods that can be accessed in transactions:
// Access party's address directlyUser;
// In Cardano, get party's stake credentialTreasury.stake_credential;
// In Cardano, get party's payment credentialTreasury.payment_credential;
Best Practices for Using Parties
-
Use descriptive names - Names like
LiquidityProvider
are clearer thanParty1
-
Consistent roles - Each party should have a well-defined role in the protocol
-
Security considerations - Be clear about which parties need to authorize actions
-
Documentation - Document the responsibilities and expectations for each party