Ethereum: Comprehension of the assembly and implementation of script in P2TR expenses (Taproot spending)
As Bitcoin script has become a solid understanding and implementation of the assembly and implementation of the taproot (P2PKH), we are more deeply in the characteristics of the assembly of the P2TR expenses script (of Taproot).
What is P2TR?
P2TR expenses include the launch of Bitcoins of a public title previously used using Taproot (P2PKH). In other words, it recharges the same bitcoins that were originally spent on a root transaction. This allows more complicated and safe payments without the need to create new scripts or new titles.
The script assembly spends on P2TR
To execute the expenses of P2TR, we must first understand the script assembly process used by Ethereum Ropsten Testnet. The most important elements of the Ethereum script are the following:
- Input scripts : These determine how to spend the amount of entry.
- Exit scripts : These determine what they send to the recipient, as well as any additional rate or relay.
We have two main entrance script for P2TR expenses: one for the original Taproot transaction and the other a new script for repossed bitcoins.
Taproot Script input
The original Taproot transaction has an “scriptpubkey” type input script that is a couple of keys that represents the public title that will be broadcast. This input script is used as the first entry of the P2TR editions.
`Solidity
0x1 ... (Public Directorate)
Output of the Taproot Script
The Re-T-T Taproot transaction has an output script that determines how to send the amount. The "scriptpubkey" field of the output script contains the public direction to which the repaired bitcoins are sent.
Solidity
0x1 ... (Public Directorate)
Assemble script for P2TR
Now we combine these two scripts to create a P2TR expense that takes the same Taproot transaction. The solidity, Ethereum Intelligent Contracts, is used in the popular programming language to implement the general assembly.
` Solidity
Pragma solidity ^0.8.0;
Hire Taprootspend {
// Enter the original Taproot transaction script
title owner;
// Characteristic to execute P2TR expenses
EXECTEP2TR FUNCTION (Uint Sum) Public {
// Create a new entrance script for Re -Bitcoins
Turn the public betting address;
Uint256 public outputamount = 0;
// Determine the output script with the original Taproot transaction script
Function GetoutScript () Inner returns (address, Uint256) {
Return address (0x1 …, owner), quantity;
}
// Use the Taproot Re -Papque transaction to calculate the address and amount of the recipient
Turn the new Newaddress;
Uint256 public Newamount = 0;
// Determine a feature that is placed in the output script of the original Taproot transaction and calculates the appropriate Re -Bitcoins inputs
Getnewinputs () inner function returns (title [] memory, uint256 []) {
// Calculate the address address with the public direction of the original Taproot transaction
Title [] Memory recipients = Newaddress;
// Calculate the output amount in Wei
UINT256 [] memory outputs = Newuint256 (recipients.