gpt4 book ai didi

Solidity - Atomic issue impossible to exchange USDT to another token(Solidity -无法将USDT兑换为另一个代币的原子问题)

转载 作者:bug小助手 更新时间:2023-10-26 20:37:40 24 4
gpt4 key购买 nike



I have this code :

我有这样的代码:



function buy_with_stablecoins(uint _tid, uint _amount) public { // _tid = 1 = usdt, _tid = 2 = usdc

require(_tid == 1 || _tid ==2, "Invalid token id");
require(presale_time>=block.timestamp, "Presale ended");


// Calculate the amount of token to be sold.

if(_tid ==1 ){

require(usdt.allowance(msg.sender, address(this))>= _amount, "Does to have enough allownace to buy");

uint _token_amount = (rate * _amount)/(10*6);

total_sold += _token_amount;

usdt.transferFrom(msg.sender, address(this), _amount);

token.transfer(msg.sender, _token_amount);

}else{

require(usdc.allowance(msg.sender, address(this))>= _amount, "Does to have enough allownace to buy");
uint _token_amount = (rate * _amount)/(10*6);

total_sold += _token_amount;

usdc.transferFrom(msg.sender, address(this), _amount);

token.transfer(msg.sender, _token_amount);
}

_addParticipant(msg.sender); // Register participant
}


I don't know why it's not working it seems I have an error when I try to send USDT token to the presale contract the presale contract should send me my token contribution in exchange but not working...

我不知道为什么它不工作,似乎我有一个错误,当我尝试发送USDT令牌到售前合同,售前合同应该发送我的象征性贡献作为交换,但不起作用…


I tried to deploy this contract with the function buy with stablecoin but I don't understand what is the issue ?

我试着用功能Buy with stablecoin部署这个合同,但我不明白有什么问题?


更多回答

What is the exact issue you are facing?

您面临的具体问题是什么?

优秀答案推荐

Your code logic seems fine. Maybe you can Elaborate on your question.
If you thought it was code error, consider these points:token addresses, token allowance, rate calculation, token transfer function, gas limit, debugging, testing environment, transaction logs, contract deployment, external dependencies etc.

您的代码逻辑看起来很好。也许你可以详细解释一下你的问题。如果您认为这是代码错误,请考虑以下几点:令牌地址、令牌允许、费率计算、令牌传输函数、气体限制、调试、测试环境、交易日志、合同部署、外部依赖等。


更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com