How to regenerate Logic Signature address onchain for validation

Our Stateful Smart contract is minting NFTs (using InnerTxns) and we want to set the clawback address of minted NFTs to a template Logic Signature address (contract account mode). Is there a way to compile a logic sig program and generate the address onchain?

According to this link, the logic signature address is the SHA512_256(“Program”+<program bytes>). And we know it is possible to compile PyTEAL to TEAL onchain using compileTeal() method. But we were not able to successfully generate matching addresses.

Compiling a Logic Signature program also provides a result in the response. Adding this response to SHA512_256(Concat(Bytes("Program"), Bytes("base64","ASABACI="))) does generate the right address onchain.

Is there a way to reproduce this for more complex Logic Signature programs that include arbitrary inputs.


You cannot do that on-chain unfortunately. This is done off-chain. And even then, you would need to compile the TEAL code into a bytecode.

In general, I would recommend setting the clawback address to the application account of the stateful smart contract. Then you can perform all operations you want using inner transactions.

In the extremely rare case where this is not sufficient, what you can do is to generate directly the TEAL bytecode in the stateful smart contract. You need to understand how TEAL bytecode works but it’s usually a question of concatenating the right parts (prefix of TEAL bytecode until definition of the templated value, actual templated value, suffix of the TEAL bytecode).

1 Like

Thank you for the response, that makes sense. In our case, the logic for each NFT clawback address is meant to be unique and we were trying to avoid smart contract deployment for each NFT.

We’ll try to understand TEAL bytecode and see if we can successfully concatenate the right parts as you suggested. We’ll switch to stateful smart contracts if we can’t figure it out in a reasonable amount of time. I appreciate your help.