magic-js icon indicating copy to clipboard operation
magic-js copied to clipboard

Algorand Extension Cannot Sign an ASA Opt-in Transaction

Open Standaa opened this issue 4 years ago • 10 comments

✅ 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

  1. Clone this repo
  2. Add a test email in index.ts
  3. npm install && npm run dev
  4. Click on "Login With Magic!" => Wait until the address displays, I did not add a loader.
  5. Try signing an opt in Tx with a mock account
  6. 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

Repro repo here

🌎 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

Standaa avatar Nov 25 '21 16:11 Standaa

Any updates about this bug ? It is a real showstopper that you cannot receive an Algorand Token if you are using Magic.

Standaa avatar Dec 09 '21 14:12 Standaa

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?

Standaa avatar Feb 07 '22 17:02 Standaa

I've stumbled into the same problem in a proyect im working on. Any updates on this?

fmonper1 avatar Mar 17 '22 11:03 fmonper1

@harryEth Any updates on this? Three algorand related issues have been pending for over four months.

Standaa avatar Mar 17 '22 12:03 Standaa

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.

hcote avatar Mar 26 '22 23:03 hcote

@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 avatar Mar 27 '22 10:03 fmonper1

@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);
}

hcote avatar Mar 30 '22 00:03 hcote

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

fmonper1 avatar Mar 30 '22 08:03 fmonper1

Anyone looking into this?

fmonper1 avatar May 17 '22 14:05 fmonper1

@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 avatar May 18 '22 19:05 Standaa

@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.

hcote avatar Sep 20 '22 14:09 hcote