magic-js
magic-js copied to clipboard
Algorand Extension Cannot Sign an ASA Opt-in Transaction
✅ Prerequisites
- ✅ Did you perform a cursory search of open issues? Is this bug already reported elsewhere?
- ✅ Are you running the latest SDK version?
- [] Are you reporting to the correct repository (
magic-sdk)? No, the algorand extension code is closed source.
🐛 Description
If I am not mistaken the Magic Extension cannot sign an Algorand ASA opt-in transaction. This would be a major bug in the Algorand Extension as it would imply that users cannot receive ASA tokens (Algorand's ERC20 equivalent).
🧩 Steps to Reproduce
- Clone this repo
- Add a test email in
index.ts npm install && npm run dev- Click on "Login With Magic!" => Wait until the address displays, I did not add a loader.
- Try signing an opt in Tx with a mock account
- Try signing an opt in Tx with Magic => Crashes
🤔 Expected behavior
My users should be able to opt-in to ASA tokens, a prerequisite to any airdrop.
😮 Actual behavior
I get the following error: Uncaught (in promise) Error: Magic RPC Error: [-32603] Internal error: address seems to be malformed
💻 Code Sample
🌎 Environment
| Software | Version(s) |
|---|---|
@magic-ext/algorand |
0.2.0 |
algosdk |
1.12.0 |
magic-sdk |
6.2.1 |
npm |
7.24.0 |
| Browser | Firefox (95.0b11) & Brave(1.32.106) |
| Operating System | Mac OS Big Sur & Monterey |
Any updates about this bug ? It is a real showstopper that you cannot receive an Algorand Token if you are using Magic.
I just tested the latest APIs:
"@magic-ext/algorand": "^3.0.1",
"algosdk": "^1.13.1",
"magic-sdk": "^8.0.1"
It seems like this problem is still not fixed. Would you have an ETA as to when this very basic flow will be possible?
I've stumbled into the same problem in a proyect im working on. Any updates on this?
@harryEth Any updates on this? Three algorand related issues have been pending for over four months.
Hey @Standaa @fmonper1 the magic.algorand.signTransaction function only supports payment transaction types. We're working on updating it so that all transaction types are supported and when it's resolved I'll update this thread.
You could try and use magic.algorand.signGroupTransactionV2` which doesn't have that limitation in the meantime.
@Standaa I got it working using this code. It feels a bit hacky, but untill the apis get updated its the best I could come up with.
const optinToAsset = async () => {
// create the asset accept transaction
if (!address) return;
const suggestedParams = await setupClient().getTransactionParams().do();
const transactionOptions = {
from: address,
to: address,
assetIndex: Number(process.env.REACT_APP_ASA_ID as string),
amount: 0, // this is an optinTxn so amount has to be 0
suggestedParams,
};
const txn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject(transactionOptions);
console.log({ txn });
const signedTxn = await magiclink.algorand.signGroupTransactionV2([
{ txn: Buffer.from(txn.toByte()).toString('base64') },
]);
const blob = signedTxn.map((txn: string) => new Uint8Array(Buffer.from(txn, 'base64')));
const { txId } = await setupClient().sendRawTransaction(blob).do();
const result = await waitForConfirmation(setupClient(), txId, 3);
console.log({ result });
};
@fmonper1 @Standaa this should be fixed now. Once you create the Transaction object with algosdk.make...TxnWithSuggestedParams() just encode the object and pass it to magic.algorand.signTransaction(encodedTxn).
Here's a codesandbox - codesandbox.io/s/recursing-frost-lx5qgx
const sendTransaction = async () => {
let params = await algodClient.getTransactionParams().do();
const enc = new TextEncoder();
let note = enc.encode("Hello World");
let txn = algosdk.makePaymentTxnWithSuggestedParams(
publicAddress,
destinationAddress,
parseInt(sendAmount),
undefined,
note,
params
);
let encodedTxn = algosdk.encodeObj(txn.get_obj_for_encoding());
let signedTx = await magic.algorand.signTransaction(encodedTxn);
let receipt = await algodClient.sendRawTransaction(signedTx).do();
console.log(receipt);
}
The example above works out fine for sending algorand payments, but when trying to do the same with other ASAs it doesnt work.
This issue should not be closed
Anyone looking into this?
@fmonper1 Ended up dropping Magic altogether. Production feedback from friends + Lack of team responsiveness + the extensions being closed-source + the lacklustre node APIs were way too many redflags.
@Standaa @fmonper1 This has been fixed and should support all transaction types. You can test out acfg and axfer types here - https://codesandbox.io/s/recursing-frost-lx5qgx?file=/src/App.js
If either of you test it out and run into any issues please bring them back up here.