# Help doing opt-in of ASA to smart contract

**URL:** <https://forum.algorand.co/t/help-doing-opt-in-of-asa-to-smart-contract/6386>\
**Category:** General\
**Tags:** teal, smart-contracts\
**Created:** [March 31, 2022, 10:32pm UTC](https://forum.algorand.co/t/help-doing-opt-in-of-asa-to-smart-contract/6386 "2022-03-31T22:32:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![javier0rosas](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.algorand.co/javier0rosas/32/1578_2.png) [@javier0rosas](https://forum.algorand.co/u/javier0rosas)\
**Post date:** [March 31, 2022, 10:32pm UTC](https://forum.algorand.co/t/help-doing-opt-in-of-asa-to-smart-contract/6386/1 "2022-03-31T22:32:13Z")

</div>

Greetings Algofam!

I want to opt-in my smart contract into an ASA through an inner transaction. Here is my code:

```auto
    @Subroutine(TealType.none)
    def opt_in_smart_contract_to_asa(asa_id):
     
        return Seq([
        
        InnerTxnBuilder.Begin(),

            InnerTxnBuilder.SetFields({
                TxnField.type_enum : TxnType.AssetTransfer,
                TxnField.xfer_asset : asa_id,
                TxnField.asset_amount : Int(0),
                TxnField.asset_sender : Global.current_application_address(),
                TxnField.asset_receiver: Global.current_application_address(),
                TxnField.fee : Int(6_000)
                }),

        InnerTxnBuilder.Submit()
            
        ])

    @Subroutine(TealType.none)
    def opt_in_transaction():

        asa_id = Btoi( Txn.application_args[1] )
        smart_contract_asset_balance = AssetHolding.balance( Global.current_application_address(), asa_id ) 
        

        # if smart contract is not opted in to the asset, 
        # call smart_contract_opt_in_to_asa()
        return Seq([
            smart_contract_asset_balance,

            # below if statement returns 1 if the smart contract is not opted in to asset
            If( Not(smart_contract_asset_balance.hasValue()) ).
                # if smart contract is not opted in to the asset, 
                # send an opt in transaction for the asset
                Then( Seq( opt_in_smart_contract_to_asa(asa_id) ) )
                # transfer the asset to the smart contract with a rekey back to the sender
                #Then( Seq( asset_transfer(asa_id, amount)) )
            ])

```

I keep getting the following error:

```auto
TransactionPool.Remember: transaction F5PPWKTO3IJKGQMQPN2QBRHOHPDF7LUGPHRD6XJGKSZQARDQS7RQ: logic eval error: clawback not allowed: sender CCVIIUUVP74CYJJWNPKBP4DIVFQKBS37R2U3VNOHEZUMTGE5VOEZD4IN24, clawback AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ. Details: pc=144, opcodes=pushint 6000
itxn_field Fee
itxn_submit

```

Any ideas as to what may be causing it?

---

<div class="post-metadata">

**Author:** ![javier0rosas](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.algorand.co/javier0rosas/32/1578_2.png) [@javier0rosas](https://forum.algorand.co/u/javier0rosas)\
**Post date:** [April 1, 2022, 2:40am UTC](https://forum.algorand.co/t/help-doing-opt-in-of-asa-to-smart-contract/6386/2 "2022-04-01T02:40:44Z")

</div>

Changing `AssetSender` to `Sender` did the trick. What is the difference between `AssetReceiver` and `Receiver`? The documentation does not say too much about it.

---

<div class="post-metadata">

**Author:** ![fabrice](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@fabrice](https://forum.algorand.co/u/fabrice)\
**Post date:** [April 1, 2022, 1:46pm UTC](https://forum.algorand.co/t/help-doing-opt-in-of-asa-to-smart-contract/6386/3 "2022-04-01T13:46:24Z")

</div>

See [Why have both txn.sender() and txn.asset\_sender() in PyTEAL? - #2 by jannotti](https://forum.algorand.co/t/why-have-both-txn-sender-and-txn-asset-sender-in-pyteal/4729/2)

In short:

- the receiver for an Algo payment transaction is `Receiver`
- the receiver for an ASA transfer is `AssetReceiver`
- the sender is always `Sender`, except for ASA clawback/revoke transactions ([Algorand Standard Assets (ASAs) - Algorand Developer Portal](https://developer.algorand.org/docs/get-details/asa/))

---

<div class="post-metadata">

**Author:** ![lishubin](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@lishubin](https://forum.algorand.co/u/lishubin)\
**Post date:** [May 2, 2022, 9:07am UTC](https://forum.algorand.co/t/help-doing-opt-in-of-asa-to-smart-contract/6386/4 "2022-05-02T09:07:30Z")

</div>

**In other words**

- In AssetTransfer, use: Sender, AssetReceiver
- In Payment, use: Sender , Receiver

Right?

---

<div class="post-metadata">

**Author:** ![fabrice](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@fabrice](https://forum.algorand.co/u/fabrice)\
**Post date:** [May 2, 2022, 12:29pm UTC](https://forum.algorand.co/t/help-doing-opt-in-of-asa-to-smart-contract/6386/5 "2022-05-02T12:29:54Z")

</div>

Yes, unless you want clawback for AssetTransfer, which is not usual.
