I got this error “Error: address seems to be malformed”. I inspect txn object it seems all address (from, assetManager, etc) are all in decoded format (public key + checksum), which is not the address in String when I construct txn for sending Algos. I can modify the txn object after the makeAssetCreateTxn with the address in String. Then this error is gone.
Is it right to have these address in decoded format (public key + checksum) or should they remain the address in String format?
Welcome back @kctam great to see you here building. Please confirm your SDK version and how you are instantiating the client. From SDK release 1.6.1 Algodv2 is the recommended client:
let algodClient = new algosdk.Algodv2(algod_token, algod_server, algod_port);
When I build txn object with simply object definition, i.e., let txn = {...}, the txn.from is the address in String format.
When I build txn object with algosdk.makeAssetCreateTxn(), the txn.from becomes a decoded format, which is {public key, checksum}. Here I encounter the “malformed address” error message.
Just would like to know if it is why I see the “malformed address” problem.
Help me understand more about your signing account. Never post your mnemonic passphrase!
Here is an article for Working with ASA Using JavaScript. Below is a bit of the code from the tutorial related to getting from the mnemonic to the signing key for use in creating the ASA. Note: the tutorial uses the makeAssetCreateTxnWithSuggestedParams() method.
let algodclient = new algosdk.Algodv2(token, server, port);
var account1_mnemonic = "PASTE your phrase for account 1";
var recoveredAccount1 = algosdk.mnemonicToSecretKey(account1_mnemonic);
console.log("Account One: " + recoveredAccount1.addr);
let addr = recoveredAccount1.addr;
// signing and sending "txn" allows "addr" to create an asset
let txn = algosdk.makeAssetCreateTxnWithSuggestedParams(addr, note,
totalIssuance, decimals, defaultFrozen, manager, reserve, freeze,
clawback, unitName, assetName, assetURL, assetMetadataHash, params);
Share some of your code leading up to the malformed address.
var account1_mnemonic = "25-WORD-MNEMONIC";
var recoveredAccount1 = algosdk.mnemonicToSecretKey(account1_mnemonic);
console.log("Account One: " + recoveredAccount1.addr);
let addr = recoveredAccount1.addr;
( async() => {
let params = await algodclient.getTransactionParams().do();
let defaultFrozen = false;
let totalIssuance = 1000;
let decimals = 0;
let reserve = addr;
let freeze = addr;
let clawback = addr;
let manager = addr;
let unitName = "DC1";
let assetName = "dumbcoin001";
let note = new Uint8Array(0);
let assetURL = "http://someurl";
let assetMetadataHash = "";
let txn = algosdk.makeAssetCreateTxnWithSuggestedParams(addr, note,
totalIssuance, decimals, defaultFrozen, manager, reserve, freeze,
clawback, unitName, assetName, assetURL, assetMetadataHash, params);
console.log(txn);
let signedTxn = algosdk.signTransaction(txn, recoveredAccount1.sk);
console.log(signedTxn);
})().catch( e=> {
console.log(e)
})
From console log I saw a complete txn is shown. Here is the first several lines and you can see the txn.from is not address in String but a decoded format.
and it seems the line signedTxn causing the malformed address error:
Error message: Error: address seems to be malformed at Object.<anonymous> (/Users/kctam/playground/testAlgorand/node_modules/algosdk/src/encoding/address.js:13:33)
The raw signed tx looks a little different then in my example. Mine uses txn.signTxn(recoveredAccount1.sk) instead of what yours uses, algosdk.signTransaction(txn, recoveredAccount1.sk)
Thanks @rfustino. It seems the object txn created with makeAssetCreateTxnWithSuggestedParams comes with the method signTxn, which is different from if txn is simple JS object using algodsdk.signTransaction, I use the latter when sending Algos to other account before.
I finally can create ASA through the JS SDK. Lessons learned:
(1) use signTxn instead of algodsdk.signTransaction when handling Txn object created by makeAssetCreateTxnWithSuggestedParams.
(2) Although assetMetadataHash is optional, it must contain 32-char data. I make it empty and the transaction fails.