-
In this example I try to build a transaction where the UTxO to be consumed has been explicitly specified. It doesn't work, and throws the error selected_amount += i.output.amount
^^^^^^^^
AttributeError: 'TransactionInput' object has no attribute 'output' which I interpret as PyCardano being unable to query the blockchain for the output amount associated with the provided UTxO. Have I found a bug in PyCardano? Here is the code: import os
from pycardano import (
Transaction,
TransactionBody,
TransactionInput,
TransactionOutput,
TransactionBuilder,
BlockFrostChainContext,
Value,
Network,
Address,
)
from blockfrost import ApiUrls
context = BlockFrostChainContext("my-consealed-preview-project-id", base_url=ApiUrls.preview.value)
NETWORK = Network.TESTNET
# ADDRESSES
wallet2_address = 'addr_test1vznjse8fycd7dzw9usre7vka0rwjcqszuu7a26pkdrw0g8sczt0l5'
# INPUTS
tx_in = TransactionInput.from_primitive(
['4a16c4f23a1855392496650deac62eb6c1fa1887f7a2e59ee2a3a3c7b67fa733', 1])
# OUTPUTS
tx_out = TransactionOutput(address=wallet2_address, amount=Value(5000000))
# BUILD TRANSACTION
tx_builder = TransactionBuilder(context)
tx_builder.add_input(tx_in);
tx_builder.add_output(tx_out);
tx_builder.build() |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Please try |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
As cffls' answer states, # Recall that my objective is to consume a specific UTxO, now determined by variable 'tx_in_input'
# ADDRESSES
wallet1_address = 'addr_test1vq8y2nlht8ek0elatvksa5ctg6u4eatrj6hhqz3ln9ca0gsn3cnam'
wallet2_address = 'addr_test1vznjse8fycd7dzw9usre7vka0rwjcqszuu7a26pkdrw0g8sczt0l5'
# INPUTS
tx_in_input = TransactionInput.from_primitive(
['4a16c4f23a1855392496650deac62eb6c1fa1887f7a2e59ee2a3a3c7b67fa733', 1])
tx_in = next(
(
u for u in context.utxos(wallet1_address)
if u.input == tx_in_input
),
None
)
# OUTPUTS
tx_out = TransactionOutput(address=wallet2_address, amount=Value(5000000))
# BUILD TRANSACTION
tx_builder = TransactionBuilder(context)
tx_builder.add_input(tx_in);
tx_builder.add_output(tx_out);
tx_builder.build() The only drawback is that it is not enough to know |
Beta Was this translation helpful? Give feedback.
tx_in
defined in your script should be aUTxO
type instead of aTransactionInput
.