I'm using tact and I haven't found any resources that do this successfully: withdraw the tokens that were sent to the smart contract into a specified address.
I have attempted this code to withdraw from the smart contract to an address that I specify within the msg (the msg.recipient in the Payout struct). This is just the part that displays the two aspects related to the payouts. The other parts of the smart contract work.
message Payout {
recipient: Address;
amount: Int as coins;
}
// Payout a specific amount to a specified address
receive(msg: Payout){
self.requireOwner();
require(msg.amount > 0, "Payout amount must be greater than zero");
require(myBalance() >= (msg.amount + self.MinTonForStorage), "Insufficient balance for payout");
send(SendParameters{
// bounce is set to true by default
to: msg.recipient,
value: msg.amount,
mode: SendIgnoreErrors, // will send the message despite any errors
}
);
}
When I run it however, the call to the contract fails. Yet it passes if the recipient is the sender itself. I don't know why that is happening. Is there a way to withdraw the smart contract's tokens to a specified address?
I managed to solve it. The code works, my issue lay within the deployment of the contract. I was trying to deploy to an existing address, thinking it would change the contract's state but a contract is immutable. Hence the function did not even exist on that contract, which resulted in the errors.