All, is there a good formula to calculate future round time on the HTLC contract? Rough math got me 20,381 rounds per day. But if a user wants a timeout 30 days in future, is 20381x30 correct or is there any other way to compute?
Itās little difficult for me.Iām not a a dĆ©velopper to write TEAL code.
Can you help me? Please.
Have you looked at using PyTeal to write smart contracts in python?
https://developer.algorand.org/docs/features/asc1/teal/pyteal/
You may also take a look on AlgoNim solution, in which you can find an overview of game architecture (there is also a link to a presentation with the original sketch of the prototype) that leverages also ASC1s, this will help you read and understand the how the rules of the game have been translated into TEAL programs using PyTeal.
Feel free to reach me out for questions.
I wrote a TEAL contract that I was hoping would be a simple contract that let people send Algo and receive an Asset. However I am getting this error when trying to fund the contract. asset 127494380 missing from
Here is my Teal. Thanks for help.
// - 127494380: ID of the transferred asset
// - 25: exchange rate N/D
// - 1000000: exchange rate N/D
// - 1000: the round at which the account expires
// - 3ELOPICTSZ5Y4W4VKXG533NEN6UBT3G5AGXXYWTA5OSDZ3DEN2ZAGOD24M: the address to refund funds to on timeout
// - 10000: maximum fee used by the limit order transaction
// - 25: the minimum amount (of asset) to be traded away
global GroupSize
int 1
==
bnz oneTx
global GroupSize
int 2
==
txn GroupIndex
int 1
==
&&
txn TypeEnum
int 4
==
&&
txn AssetAmount
int 25
>
&&
txn XferAsset
int 127494380
==
&&
txn AssetSender
global ZeroAddress
==
&&
txn AssetCloseTo
global ZeroAddress
==
&&
gtxn 0 TypeEnum
int 1
==
&&
gtxn 0 Receiver
addr 3ELOPICTSZ5Y4W4VKXG533NEN6UBT3G5AGXXYWTA5OSDZ3DEN2ZAGOD24M
==
&&
gtxn 0 Amount
int 1000000
mulw
store 2
store 1
txn AssetAmount
int 25
mulw
store 4
store 3
load 1
load 3
>
bnz done
load 1
load 3
==
load 2
load 4
>=
&&
bnz done
err
oneTx:
txn TypeEnum
int 1
==
txn CloseRemainderTo
addr 3ELOPICTSZ5Y4W4VKXG533NEN6UBT3G5AGXXYWTA5OSDZ3DEN2ZAGOD24M
==
&&
txn FirstValid
int 1000
>
&&
txn Receiver
global ZeroAddress
==
&&
txn Amount
int 0
==
&&
txn TypeEnum
int 4
==
txn AssetSender
global ZeroAddress
==
&&
txn XferAsset
int 127494380
==
&&
txn AssetAmount
int 0
==
&&
txn AssetCloseTo
addr 3ELOPICTSZ5Y4W4VKXG533NEN6UBT3G5AGXXYWTA5OSDZ3DEN2ZAGOD24M
==
txn FirstValid
int 1000
>
&&
txn AssetReceiver
global ZeroAddress
==
&&
txn AssetReceiver
txn Sender
==
txn AssetCloseTo
global ZeroAddress
==
&&
txn LastValid
int 1000
<
&&
||
&&
||
done:
txn Fee
int 10000
<=
&&
Hello and welcome to the Algorand Community!
On a quick look, seems like this may be related to the question asked here: Optins to TEAL Managed Account
Have you opted the contract account into asset 127494380? Add some code to allow it to opt it in, then issue that opt-in transaction before you make a trade. Without that, the contract wonāt be able to receive the asset.
Thank you for the reply. Iām handwriting the Teal in AlgoStudio SDK and compiling that way to push to TestNet then I found ALGODesk.io has a teal debugger and compiler also. I think this would be correct but Iām not 100%.
int OptIn
txn OnCompletion
==
The code there is related to opting into a stateful application.
Opting into an asset is just an asset transfer of 0 to and from the account opting in. Here is what the opt-in transaction structure looks like for assets: Structure - Algorand Developer Portal
Since I donāt have all context of your app, please take the following suggestions with that in mind as a heavy disclaimer and make sure to do your own security auditsā¦
The asset opt-in scenario could be weaved in under the onetx
scenario (because you want to make sure only a single transaction is permitted) and it would look something like:
// asset transaction type
txn TypeEnum
int 4
==
&&
// opt-ins are transfers of 0 amount
txn AssetAmount
int 0
==
&&
// the sender must be equal to the receiver for opt-ins. And the sender for contract accounts is the contract account.
txn Sender
txn AssetReceiver
==
&&
// make sure it is opting in to the right asset
txn XferAsset
int 127494380
==
&&
// Add any checks to restrict unintended loopholes - this is important; make sure I'm not missing any!
txn AssetSender
global ZeroAddress
==
&&
txn AssetCloseTo
global ZeroAddress
==
&&
// Add an expiration round if you can as a best practice
txn LastValid
int EXPIRATION_ROUND
<
&&
Then next steps would be:
- Send algos to contract to initialize it on chain (201,000 microAlgos to cover minimum balance for Algos and one asset holding, plus money for a fee).
- Send opt-in transaction from contract account to opt it into asset: 127494380.
- If you want, and youāre super paranoid like me, wait until the expiration round has passed and then add more funds to cover fees. That way you can eliminate any unforeseen attack vectors through that additional code
- Fund the account with the asset and let the trades begin!
By the way, I didnāt see any checks for rekeying in your code which is very important. See some more related guidelines here. Relevant line:
Always verify that the
RekeyTo
property of any transaction is set to theZeroAddress
unless the contract is specifically involved in a rekeying operation.
Edit (2/28): Wrong field name; changed Receiver
to AssetReceiver
.
Thank you very much for the replies. It is starting to be more clear now for me. I was definitely confusing the the docs and got turned around. When I get off work from my day job tonight I will work on my project and try to compile and test again. Hopefully I get it to work and will share the end results with everyone. I need to comment my code better too. Thanks for the excellent explanation too. Big eye opener for me. My lightbulb moment.
Can you point me to the docs for opt-in a transaction from a contract account? With AlgoStudio I have a test optin.json file which I can test sign with to opt-in a wallet account to an asset. But I am having trouble finding docs on how to do this for a contract account. I do not have the mnemonic of the contract account or I could simply add it to algo signer or a mobile wallet and add an asset that way. Iām going to have to retrain my brain some also. Was used to writing and compiling in Solidity for Ethereum. Algo is easier especially with TEAL it is so effiecent I just have to figure out the process Which you have helped me tremendously already. Please also share your algo wallet as I would be happy to send you some algo to say thanks for helping me figure this out.
I think I figured it out thanks to this boiler plate. Algorand Developer Portal
Hi @StishSits glad to hear that my solution was helpful! I go through all the process step by step so you will find the whole deployment of an Algorand dApp explained there.
Please note that all the process can be handled using your favorite SDK instead of do it manually with goal.
Hi @liz I hope all is well! I have been working on this for a few weeks without much luck. I created a Repository for my code and to document my progress. Currently, I am stuck hacking through this Issue, which I defined on GitHub.
Command Line Input: goal clerk compile stateless_swap.teal
Output Error: Cannot contact Algorand node: open /Users/brianhaney/node/data/algod.net: no such file or directory
I am struggling to structure a path to solve the Issue. More generally, I am wondering if it is possible to solve the problem I defined with TEAL.
Problem: How to successfully execute an Algorand Smart Contract to transfer value using TEAL?
I know that TEAL is an execution language, and my understanding is that TEAL is mostly used for validating contracts. I started generating .teal
scripts using PyTeal, but I have not been able to run or write any TEAL programs. Iām also still struggling to understand the syntactic structure for TEAL software. Alternatively, I may need to change the Problem.
Alternative Problem: How to successfully validate a transaction using TEAL?
Iām wondering if this would be a better problem definition for a TEAL program. However, I am not sure whether I would validate an existing contract or whether I would need to write additional code to first execute a new transaction. For example, would it be possible to use TEAL to validate a LaylaCoin transaction? I was hoping you may be able to provide guidance. I know you are super busy and I really appreciate your time. Thank you!
For the first issue, you need to start the node: goal node start
TEAL can be used in two ways: stateful and stateless.
Have you read Smart Contract Overview - Algorand Developer Portal?
I would also recommend you doing this tutorial which is more hands-on and introduce stateless smart contracts slowly: GitHub - algorandfoundation/buildweb3: Repository for the Algorand class of the "Building with Blockchain for Web 3.0" course (https://buildweb3.org)
In short, for your problem, you need to use a pattern with an escrow account. See Example Crowdfunding Stateful Smart Contract Application | Algorand Developer Portal
For your second problem, what do you mean by āvalidating a LaylaCoin transactionā?
If you mean, restricting the kind of transactions that can be done with LaylaCoin, see Using a Smart Contract for Advanced Approvals: Hierarchical Thresholds | Algorand Developer Portal
If you mean, selling LaylaCoin for Algos, just read GitHub - algorandfoundation/buildweb3: Repository for the Algorand class of the "Building with Blockchain for Web 3.0" course (https://buildweb3.org)
Thank you. This paves a clear path forward. Iām going to work through the resources you provided. I appreciate your guidance here.