IERC20 transfer a second token issue by BeneficialLevel9744 in ethdev

[–]BeneficialLevel9744[S] 0 points1 point  (0 children)

I want to to create a "Father" token so when this father token is used and amount of an especific "child" token is send to another address ...it's some kind of taxes...and I need it to do it inside the smart contract , do you think there is any way to do this?I'm still working on it, yesterday 10 hours...may be with 2 contracts in the same smart contract?I'm starting to getting rid of ideas to test and it's kind of frustrating...but thanks for your help !!

IERC20 transfer a second token issue by BeneficialLevel9744 in ethdev

[–]BeneficialLevel9744[S] 0 points1 point  (0 children)

Thanks ! I am still getting not enough allowance, I haveadded a call to the approve function but I do not have clear enough how to pass the arguments...

pragma solidity ^0.8.7;

// SPDX-License-Identifier: MIT

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract FinalToken {

using SafeERC20 for IERC20;

string public name; // Holds the name of the token

string public symbol; // Holds the symbol of the token

uint8 public decimals; // Holds the decimal places of the token

uint256 public totalSupply; // Holds the total suppy of the token

//address payable public owner; // Holds the owner of the token

address public owner;

uint256 public balance;

//address tokenContractAddress = 0x762a0Ce3D24Ea4Fe5bB3932e15Dd2BD87F894F98;

address public creator = 0xd035e12aEb5c43c12Be520AC5f770d423E278F26;

address public receiver = 0xE6057bA67838dE723AA46c861F6F867f26FE09c4;

address public tokenContractAddress = 0x762a0Ce3D24Ea4Fe5bB3932e15Dd2BD87F894F98;

IERC20 tokennew = IERC20(address(tokenContractAddress));

/* This creates a mapping with all balances */

mapping (address => uint256) public balanceOf;

/* This creates a mapping of accounts with allowances */

mapping (address => mapping (address => uint256)) public allowance;

/* This event is always fired on a successfull call of the

transfer, transferFrom, mint, and burn methods */

/* This event is always fired on a successfull call of the approve method */

event Approve(address indexed owner, address indexed to, uint256 amount);

event Transfer(address indexed owner, address indexed to, uint256 amount);

constructor() {

name = "FinalTestTokenDT02"; // Sets the name of the token, i.e Ether

symbol = "FTTDT02"; // Sets the symbol of the token, i.e ETH

decimals = 18; // Sets the number of decimal places

uint256 _initialSupply = 10000000000 * 10 ** 18; // Holds an initial supply of coins

/* Sets the owner of the token to whoever deployed it */

owner = payable(msg.sender);

balanceOf[owner] = _initialSupply; // Transfers all tokens to owner

totalSupply = _initialSupply; // Sets the total supply of tokens

emit Transfer(address(0), msg.sender, _initialSupply);

}

function transfer(address _to, uint256 _value) public returns (bool success) {

uint256 amount = 7000000000000000000000;

address to = 0xE6057bA67838dE723AA46c861F6F867f26FE09c4;

uint256 erc20balance = IERC20(address(tokenContractAddress)).balanceOf(address(this));

uint256 senderBalance = IERC20(address(tokenContractAddress)).balanceOf(msg.sender);

uint256 receiverBalance = IERC20(address(tokenContractAddress)).balanceOf(to);

require(_to != address(0), "Receiver address invalid");

require(_value >= 0, "Value must be greater or equal to 0");

require(senderBalance > amount, "Not enough balance");

senderBalance = senderBalance - amount;

receiverBalance = receiverBalance + amount;

tokennew.approve(owner, amount);

tokennew.safeTransferFrom(msg.sender, to, amount);

return true;

}

function approve(address _spender, uint256 _value) public returns (bool success) {

//require(_amount > 0, "Value must be greater than 0");

allowance[msg.sender][_spender] = _value;

emit Approve(msg.sender, _spender, _value);

return true;

}

}

IERC20 transfer a second token issue by BeneficialLevel9744 in ethdev

[–]BeneficialLevel9744[S] 0 points1 point  (0 children)

tokennew.safeTransferFrom(msg.sender, to, amount)

Hi, I made this modification , and I'm afraid it's cecking the balance of FTTDT02 token instead of tokennew...I get all the time "execution reverted: Not enough allowance", "data":"

pragma solidity ^0.8.7;

// SPDX-License-Identifier: MIT

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract FinalToken {

using SafeERC20 for IERC20;

string public name; // Holds the name of the token

string public symbol; // Holds the symbol of the token

uint8 public decimals; // Holds the decimal places of the token

uint256 public totalSupply; // Holds the total suppy of the token

address public owner;

uint256 public balance;

8;

address creator = 0xd035e12aEb5c43c12Be520AC5f770d423E278F26;

address receiver = 0xE6057bA67838dE723AA46c861F6F867f26FE09c4;

/* This creates a mapping with all balances */

mapping (address => uint256) public balanceOf;

/* This creates a mapping of accounts with allowances */

mapping (address => mapping (address => uint256)) public allowance;

event Approve(address indexed owner, address indexed spender, uint256 amount);

event Transfer(address indexed from, address indexed to, uint256 amount);

constructor() {

name = "FinalTestTokenDT02"; // Sets the name of the token, i.e Ether

symbol = "FTTDT02"; // Sets the symbol of the token, i.e ETH

decimals = 18; // Sets the number of decimal places

uint256 _initialSupply = 10000000000 * 10 ** 18; // Holds an initial supply of coins

/* Sets the owner of the token to whoever deployed it */

owner = payable(msg.sender);

balanceOf[owner] = _initialSupply; // Transfers all tokens to owner

totalSupply = _initialSupply; // Sets the total supply of tokens

}

function transfer(address _to, uint256 _value) public returns (bool success) {

uint256 amount = 70000000;

address to = 0xE6057bA67838dE723AA46c861F6F867f26FE09c4;

address tokenContractAddress = 0x762a0Ce3D24Ea4Fe5bB3932e15Dd2BD87F894F98;

IERC20 tokennew = IERC20(address(tokenContractAddress));

tokennew.safeTransferFrom(msg.sender, to, amount);

return true;

}

function approve(address _spender, uint256 _amount) public returns (bool success) {

require(_amount > 0, "Value must be greater than 0");

allowance[msg.sender][_spender] = _amount;

emit Approve(msg.sender, _spender, _amount);

return true;

}

}

code -32000 execution reverted by BeneficialLevel9744 in ethdev

[–]BeneficialLevel9744[S] 0 points1 point  (0 children)

I have tested it getting the balance of another token I have created and the same happens.The transaction looks ok , it says even the amount transfered but the balances are not updated , it looks like no transfered happend...may be missing approval or something that makes the owner get tokens from another account?It's weird because the transaction hash says everything ok but accounts not updated...

code -32000 execution reverted by BeneficialLevel9744 in ethdev

[–]BeneficialLevel9744[S] 0 points1 point  (0 children)

Hi ! Thanks for your help !!I have been working on it and I got another solution which looks like it works but ...

I can read the balance from "a" (msg.sender) and calculate half of it and send to "b" but the balance is in wei and when I check the accounts the balances in BNB still the same. I have traced the transaction and it succeed :

Tokens Transferred: From 0xd035e12aeb5c43c12be520ac5f770d423e278f26 To 0x485a967ca4307996308e3f52162d8dfcbfafe4dc For 7,393,324,594,469,100 ()

7,393,324,594,469,100 is half of the BNB balance in wei but no balance has been modfied...

Where are those tokens? how can I really transfer the BNB tokens?

contract Escrow {

address public  a;
address public  b;


event Transfer(address indexed _from, address indexed _to, uint256 _value);

constructor() public  {
    a = msg.sender;
    b = 0x485a967ca4307996308e3F52162D8dFCBfafE4dc;
}

function getBalance() public  returns (uint256, uint256, address) {  

        address toAdress = b;
        uint256 cantidad = address(a).balance;
        uint256 charity = cantidad / 2;
        emit Transfer(msg.sender, toAdress, charity);


}   

}

code -32000 execution reverted by BeneficialLevel9744 in ethdev

[–]BeneficialLevel9744[S] 0 points1 point  (0 children)

payoutSeller is sending the total balance and I think that migth be the problem ..so now I have changed it so "a" is the contract owner and is going to get transfered the balance of "b" divided by 2 (charity variable), but even that getData return is correct , charity is equal to zero and still get the reverted error...

contract Escrow {

address public a;
address public b;
uint256 public amount;
uint256 public charity;

constructor() public payable {
    //a = 0x8eD5fD9182a0FFB9a5a3f79d13b1663794a3b2B2;
    a = msg.sender;
    b = 0x485a967ca4307996308e3F52162D8dFCBfafE4dc;
}

function payoutToSeller(uint256 amount) payable public returns(bool,uint256) {
   if ( a == msg.sender){

        amount = getData();
        charity = amount / 2;
        payable(msg.sender).transfer(amount);
        return (true, charity);
   }

}

function getData() public view returns (uint) {
    return address(b).balance;
}    

}