最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

smartcontracts - How do I send a payment to an address other than the sender from a TON smart contract? - Stack Overflow

programmeradmin0浏览0评论

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'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?

Share Improve this question asked Jan 31 at 8:26 AnonAnon 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论