Algosigner, How do I sign an opt-in application transaction. Specifically appArgs is giving me issues

I’m learning the SDKs and in the process of building a simple app in order to better understand how the heck it all works.

I’ve deployed an app to the testnet (app-id 15014315).

I’ve had no issues interacting with this app in python using PyTeal and algosdk.

I’m now trying to interact with this app using Algosigner and javascript.

In my testing in python, I was able to OptInto the contract without passing any arguments. I can then call the application as many times as I want and pass “Again” as the argument.

My two questions are, how do I create an Application OptIn transaction in Javascript using AlgoSigner? and how do I properly format the appArgs?

I would expect the below to work, but i receive “TEAL runtime encountered err opcode” when executing the signTransaction()

function signTransaction(){
  AlgoSigner.sign({
    type: 'appl',
    from: document.getElementById('from').value,
    appArgs: ["Again"],
    fee: txParams['fee'],
    firstRound: txParams['last-round'],
    lastRound: txParams['last-round'] + 1000,
    genesisID: txParams['genesis-id'],
    genesisHash: txParams['genesis-hash'],
    appIndex: 15014315
  })
  .then((d) => {
    signedTx = d;
  })
  .catch((e) => {
    console.log(e);
  });
}

function sendTransaction(){
  AlgoSigner.send({
    ledger: 'TestNet',
    tx: signedTx.blob
})
}

If I change the appArgs to the following then the signTransaction function works. But when I go to send the transaction I get the error “invalid ApplicationArgs index 0”
appArgs: null,

If I change the appArgs to just have the string “Again” in it. Then the signTransaction functionr eturns the error “appArgs must be an Array of Uint8Array.”
appArgs: "Again",

How can I create a Unit8Array containing just one argument, which would be the word “Again”?

Thanks for whoever reads this and is able to help!

Welcome @algomage to building on Algorand, glad you are here!

The primary purpose of AlgoSigner is a transaction signer for WebApps. I’m inferring from your OP that you used the Python SDK with a mnemonic to build, sign and send your App Create transaction. Nicely done!

Going forward, you may use any SDK to build your transactions, then present the unsigned transaction to AlgoSigner which will take care to sign and send it. Your WebApp code will not contain the mnemonic, as the key is stored within your user’s AlgoSigner. Have a look at the Smart Contract documentation for Using the SDKs to build the optin transaction. Once your SDK builds the unsigned txn just call AlgoSigner.sign(txn) then determine how you want to handle the returned signed transaction blob. You may send to a local node or AlgoSigner.

Calling your app with arguments will require encoding string data as base64. This is SDK specific, so take a look at the calling with arguments section of the docs.

Have fun building!

1 Like