Ask coding questions

← Back to all posts
Uint8Array error - not valid datatype (but runs fine in debugger)
rfustino

The replit is here:
https://replit.com/@Algorand/ASAIntegrationsJS#index.js

Blows up on line 149 when I run it (error: metadata should be uint8array or string). When I debug it, it works. When I run it locally it works too. Please advise as I am sure this error is on replit end.

let metadatafile = {
"name": "ALICECOI",
"description": "Alice's Artwork Coins",
"image": "https:\/\/s3.amazonaws.com\/your-bucket\/images\/MyPicture.png",
"image_integrity": "sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
"properties": {
"simple_property": "Alice's first artwork",
"rich_property": {
"name": "AliceCoi",
"value": "001",
"display_value": "001",
"class": "emphasis",
"css": {
"color": "#ffffff",
"font-weight": "bold",
"text-decoration": "underline"
}
},
"array_property": {
"name": "Artwork Coins",
"value": [1, 2, 3, 4],
"class": "emphasis"
}
}
};
const hash = crypto.createHash('sha256');
hash.update(metadatafile);
const metadata = new Uint8Array(hash.digest());
// blows up on next line
let txn = algosdk.makeAssetCreateTxnWithSuggestedParams(addr, note,
totalIssuance, decimals, defaultFrozen, manager, reserve, freeze,
clawback, unitName, assetName, assetURL, metadata, params);

Voters
rfustino
Comments
hotnewtop
rfustino

refactored some code. error now on line 144. But runs fine in debug mode. To be clear error is still happening when running without debug. Please escalate, we are going into production on 9/28
// this is the line
const txn = algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject({
from: alice.addr,
total,
decimals,
assetName,
unitName,
assetURL: url,
assetMetadataHash: metadata,
defaultFrozen,
freeze: freezeAddr,
manager: managerAddr,
clawback: clawbackAddr,
reserve: reserveAddr,
suggestedParams: params,});

err Error: assetMetadataHash must be a 32 byte Uint8Array or string.
at new Transaction (/home/runner/ASAIntegrationsJS/node_modules/algosdk/dist/cjs/src/transaction.js:208:23)