akegaviar / ton-foo

MIT License
0 stars 0 forks source link

Access TONs in Jetton contract type wallet #514

Open akegaviar opened 4 months ago

akegaviar commented 4 months ago

hey i wrote smart contract that allow users to send TONs to smart contract address and receive my jettons,everytime i mint new jettons and burn these on my main wallet (im not sure if thats good way but i couldnt find a way to "transfer" these). TON's are on my smart contract wallet but i cant really find a way to access them, how do i do that? Do i need to somehow transfer them to different wallet after every user transaction, how can i code that? Thanks.

smart contract code: https://mystb.in/RingsVaultDiploma

Answer

If those TONs are locked in your contract you do not have any other option other than having a receiver to withdraw contract's balance. So you need to implement a new operation to withdraw desired amount of TON coins to a specific receptient.

for example:

if (op == op::withdraw()) {
        throw_unless(73, equal_slices(sender_address, admin_address));
        slice to_address = in_msg_body~load_msg_addr();
        int amount = in_msg_body~load_coins();

        ;; send raw message to "to_address" with specified withdraw "amount"
        ;; consider reserving some ton coins for storage and future fees

        return ();
}

Original