Comments (7)
Notice the first image has a native asset with quantity of only 1 , whereas the second image is a ss from cardano showing 2.
It's worth noting that my front-end is also pulling from blockfrost (via nodejs) and showing the correct amount..
from pycardano.
What seems to be the issue here? As far as I can tell there's two UTxOs, each have the Xymbol token with a quantity of 1. So a total of 2 for the address, as shown on Cardanoscan. What I think you're doing on the front-end is querying Blockfrost's asset addresses endpoint assets/{asset}/addresses
, however in Pycardano you're querying utxos, so you'll need to sum them up
from pycardano.
@34r7h please read a little bit about how the UTXO model works. The data reported are correct.
from pycardano.
@Et9797 you're right, my mistake. Been a long struggle to get systems working and twice before BF data wasn't updating so I jumped to an incorrect conclusion. Thanks for helping me see.
from pycardano.
@Et9797 i get two utxos from the same tx id when the utxo is a minting tx. difficult to build a change function. can you recommend a good way to handle this scenario:
─────────────────────────
utxos_from_bf: <class 'list'>
───────────────
0: {'input': {'index': 0,
'transaction_id': TransactionId(hex='12a3c696904332e678dc4897b343e111dd688caa9e567e24255aa3a8bd84c754')},
'output': {'address': addr1q9nzv2662ey4kkx96makz82q99wwzehs2uzrt9wwyttq723xkkkcpe0xgfzya3g0jzz825fyfzwm7melppsjr3uw72qs7am8ys,
'amount': {'coin': 1379280,
'multi_asset': {ScriptHash(hex='ef86d15fdc26f796f22582bdafa4369d13e8cd47ef0480b6f57dc899'): {AssetName(b'Panjtara Token'): 1}}},
'datum_hash': None}}
1: {'input': {'index': 1,
'transaction_id': TransactionId(hex='12a3c696904332e678dc4897b343e111dd688caa9e567e24255aa3a8bd84c754')},
'output': {'address': addr1q9nzv2662ey4kkx96makz82q99wwzehs2uzrt9wwyttq723xkkkcpe0xgfzya3g0jzz825fyfzwm7melppsjr3uw72qs7am8ys,
'amount': {'coin': 2428467, 'multi_asset': {}},
'datum_hash': None}}
from pycardano.
@Et9797 i get two utxos from the same tx id when the utxo is a minting tx. difficult to build a change function. can you recommend a good way to handle this scenario:
───────────────────────── utxos_from_bf: <class 'list'> ─────────────── 0: {'input': {'index': 0, 'transaction_id': TransactionId(hex='12a3c696904332e678dc4897b343e111dd688caa9e567e24255aa3a8bd84c754')}, 'output': {'address': addr1q9nzv2662ey4kkx96makz82q99wwzehs2uzrt9wwyttq723xkkkcpe0xgfzya3g0jzz825fyfzwm7melppsjr3uw72qs7am8ys, 'amount': {'coin': 1379280, 'multi_asset': {ScriptHash(hex='ef86d15fdc26f796f22582bdafa4369d13e8cd47ef0480b6f57dc899'): {AssetName(b'Panjtara Token'): 1}}}, 'datum_hash': None}} 1: {'input': {'index': 1, 'transaction_id': TransactionId(hex='12a3c696904332e678dc4897b343e111dd688caa9e567e24255aa3a8bd84c754')}, 'output': {'address': addr1q9nzv2662ey4kkx96makz82q99wwzehs2uzrt9wwyttq723xkkkcpe0xgfzya3g0jzz825fyfzwm7melppsjr3uw72qs7am8ys, 'amount': {'coin': 2428467, 'multi_asset': {}}, 'datum_hash': None}}
Not exactly sure what you're after. If you're just trying to get the balance of an address you can simply use the api function from Pycardano's Blockfrost chain context like so:
from pycardano import *
NETWORK = Network.TESTNET
chain_context = BlockFrostChainContext(
project_id="API_KEY_HERE",
network=NETWORK
)
nami_address = Address.from_primitive("YOUR_ADDR")
balance = chain_context.api.address(str(nami_address))
print(balance)
Now parse the tokens/ADA from the returned Namespace object. Note: the ADA amount is including collateral + Ada locked with assets. So don't be confused if Nami shows a slightly lower amount than that (provided you're using Nami).
from pycardano.
Cheers, @Et9797
I'm not using Nami, I'm building a wallet interface in my project. Lot's of things work until edge cases come up, such as the token retainers and returns not meeting minimum requirements. It's difficult to reason about this considering there's not much of a difference between a minting transaction and another utxo when balancing inputs and outputs.
Is there a way besides checking via blockfrost.BlockFrostApi.asset(asset_policy)
if a utxo is a minting utxo containing unspendable ada? I think really this is a problem cardano should address at it's core else I would think many developers will be addressing the same issue continuously.
from pycardano.
Related Issues (20)
- PlutusData parsing does not handle modern type hints HOT 8
- Support for CIP14
- Fee off by 1 HOT 3
- tx sign fails without giving any explicit error. Error type: 500 HOT 2
- most basic nft minting is now failing HOT 9
- Support for Ogmios 6.x in the ChainContext HOT 3
- Seperating primitives and chain contexts / higher level tooling HOT 1
- TransactionFailedException with empty websocket response / receiving empty string
- Reconstructing Transactions from CBOR does not preserve the structure HOT 7
- Support Conway HF ledger changes HOT 1
- Integration test for Conway HF
- Usage of PlutusData for Datum deserialization is unclear HOT 9
- Pycardano does not prevent adding datums for script inputs with inline datums
- Round trip plutus datum serialization/deserialization error HOT 4
- Creating an invalid tx when trying to mint too large amount of tokens HOT 5
- Error message misleading when execution/mem cost largely exceeds allowed cost
- TypeError when computing tx id: Field 'datum' should be of type typing.Union[...] HOT 1
- PyCardano creates an imbalanced transaction in complex transactions HOT 1
- [bug]: BlockFrostChainContext is not correctly initialized HOT 3
- cardano-cli context incorrect handling latest protocol params
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycardano.