Pyteal Question: Smart Contract Asset Opt-ins?

Afternoon all,

I have a method in a smart contract for some opt-ins like so:

def stakeAssetsOptin():
    return Seq([
        InnerTxnBuilder.Begin(),
        InnerTxnBuilder.SetFields({
            TxnField.type_enum: TxnType.AssetTransfer,
            TxnField.xfer_asset: Int(833815143),
            TxnField.asset_amount: Int(0),
            TxnField.asset_receiver: Global.current_application_address(),
        }),
        InnerTxnBuilder.Submit(),

. . . 
. . .

However, when I try to call this method with the code below, I receive:

algosdk.error.AlgodHTTPError: TransactionPool.Remember: transaction XLU23PGAKAKBP54MW4HBCOJ45ELYPNT2FRNOST65NPEZARY3KEQQ: logic eval error: unavailable Asset 833815143. Details: pc=616, opcodes=itxn_field TypeEnum; intc 5 // 833815143; itxn_field XferAsset

    sender=sender_address,
    sp=params,
    index = app_id,
    app_args = [0x3e6c9ef4.to_bytes(4, 'big')],
    on_complete= OnComplete.NoOpOC
    )

The docs say an unavailable asset means it doesn’t exist, but I’m on mainnet (where the smart contract is also launched and I am sending transactions from). To be clear, I am trying to opt my smart contract into some assets.

Any assistance would be appreciated, thank you!

Edit: Just FYI I also tried this for my method and also didn’t work:

        InnerTxnBuilder.Begin(),
        InnerTxnBuilder.SetFields({
            TxnField.type_enum: TxnType.AssetTransfer,
            TxnField.xfer_asset: Int(833815143),
            TxnField.on_completion: OnComplete.OptIn
        }),
. . .
. . .

UPDATE: Was able to get it to go through by including the foreign assets in the application call args and using my original method at the top of this post, thank you

Great that you were able to figure it out @Atsoc1993 :+1:

1 Like

In the future, you can contact the developer relations team in discord. Also there is a kappa bot in discord which will provide you with relevant information if the question is generic.

1 Like

This is actually great advice and exactly what I did! I utilized the discord and got advice from a fellow dev and some feedback from Kapa—I wanted to utilize all resources so also posted here in case anyone was online. Didn’t want to be stuck for too long haha

1 Like