Skip to content
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

can't get decoded tags #210

Closed
daniel-deepmedia opened this issue Apr 14, 2023 · 2 comments · Fixed by #211
Closed

can't get decoded tags #210

daniel-deepmedia opened this issue Apr 14, 2023 · 2 comments · Fixed by #211

Comments

@daniel-deepmedia
Copy link

daniel-deepmedia commented Apr 14, 2023

Hi, I tried to run the code below:

const transaction = await arweave.transactions.get(txid);
const tags = transaction.get('tags', {'decode': true, 'string':true}) as Object as Tag[]

but I run into the error:

TypeError: b64UrlString.replace is not a function
    at b64UrlDecode (/Users/...../node_modules/arweave/node/lib/utils.js:81:33)

while this works, but gives me the tags encoded:

const transaction = await arweave.transactions.get(txid);
const tags = transaction.get('tags') as Object as Tag[]

which is not what I want, so I had to do it this way:

import { b64UrlToString } from 'arweave/node/lib/utils.js'
const transaction = await arweave.transactions.get(txid);
const tags = (transaction.get('tags') as Object as Tag[]).map((tag: Tag) => {
    return {'name': b64UrlToString(tag.name), 'value': b64UrlToString(tag.value)}
})

Edit: I npm installed version: "arweave": "^1.13.5"

@rosmcmahon
Copy link
Member

rosmcmahon commented Apr 17, 2023

Yeah, it seems to have always been this way (I checked back through releases to 1.9 anyhow)
Ref: https://github.com/ArweaveTeam/arweave-js#decode-tags-from-transactions
So what you are doing above is sort of correct.

These need to be looked into though:

  1. Typescript is giving the return type of tags as string.
  2. The error isn't too helpful either, it's trying to perform string functions on an array

@rosmcmahon
Copy link
Member

Interesting. 1. above cannot be fixed without breaking compatibility badly.

After next patch get will throw an error if an array is detected, and decode or string are defined.

FYI, i think the preferred usage should be:

const transaction = await arweave.transactions.get(txid);
const tags = transaction['tags'] // correct type returned

this delivers type information correctly. i will update README.md to reflect this anyhow.

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

Successfully merging a pull request may close this issue.

2 participants