Skip to content

Document how to add reference_inputs when using TransactionBuilder #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
peterVG opened this issue Oct 30, 2022 · 3 comments
Closed

Document how to add reference_inputs when using TransactionBuilder #118

peterVG opened this issue Oct 30, 2022 · 3 comments

Comments

@peterVG
Copy link
Contributor

peterVG commented Oct 30, 2022

It's not obvious how to set values for the reference_inputs property and add it to a TransactionBody, as per the API here:
https://pycardano.readthedocs.io/en/latest/api/pycardano.transaction.html#pycardano.transaction.TransactionBody

I can add another TransactionBuilder property like ttl as part of the object instantiation, e.g.
builder = TransactionBuilder(context=context, ttl=2024)

But trying to do the same for the reference_inputs property results in:

builder = TransactionBuilder(context=context, reference_inputs=["testing1", "testing2"])
>>>TypeError: TransactionBuilder.__init__() got an unexpected keyword argument 'reference_inputs'

Trying to add it to the object after it's instantiated also fails to build a proper transaction:

builder = TransactionBuilder(context)`
builder.__set__(self, reference_inputs, {"test1", "test2"})
>>>AttributeError: 'TransactionBuilder' object has no attribute '__set__'. Did you mean: '__eq__'?

This code here appears to be adding reference_inputs to the utxo.output.script but, again, not sure where to initially set that reference input value.

if utxo.output.script:
self._inputs_to_scripts[utxo] = utxo.output.script
self.reference_inputs.add(utxo.input)
self._reference_scripts.append(utxo.output.script)

@cffls
Copy link
Collaborator

cffls commented Oct 30, 2022

Because reference inputs under txbuilder is an empty set by default, you need to add reference inputs like this:

builder.reference_input.add(my_input)

or this:

builder.reference_input = {my_input1, my_input2}

You can also find an example of using reference script in this test: https://github.com/Python-Cardano/pycardano/blob/main/integration-test/test/test_plutus.py#L239

@peterVG
Copy link
Contributor Author

peterVG commented Oct 30, 2022

OMG. I tried everything but that :-)

Thanks very much @cffls I can confirm this works. Just one correction, the property name should be plural e.g. builder.reference_inputs not builder.reference_input

Will return favour with a documentation PR that you may or may not want to add.

@peterVG
Copy link
Contributor Author

peterVG commented Oct 30, 2022

See PR #119

@peterVG peterVG closed this as completed Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants