Skip to main content

So basically, I want a transfer function of ERC20 tokens on 0.4.16, but I want to make it so that you can specify which token you want to transfer to another address, but everytime I try to send tokens, there's an error, I think it's because the "msg.sender" has to approve the tokens, but idk, this is the code, if you want to review it:

pragma solidity 0.4.16;

interface ERC20 { function transfer(address _to, uint256 _value) public returns (bool); }

contract TokenTransfer { function transferToken(address _tokenAddress, address _to, uint256 _value) public returns (bool) { // Create an instance of the ERC20 token contract ERC20 token = ERC20(_tokenAddress);

pragma solidity 0.4.16;

interface ERC20 {
    function transfer(address _to, uint256 _value) public returns (bool);
}

contract TokenTransfer {
    function transferToken(address _tokenAddress, address _to, uint256 _value) public returns (bool) {
        // Create an instance of the ERC20 token contract
        ERC20 token = ERC20(_tokenAddress);

        // Transfer the specified amount of tokens to the specified address
        return token.transfer(_to, _value);
    }
}

}

So basically, I want a transfer function of ERC20 tokens on 0.4.16, but I want to make it so that you can specify which token you want to transfer to another address, but everytime I try to send tokens, there's an error, I think it's because the "msg.sender" has to approve the tokens, but idk, this is the code, if you want to review it:

pragma solidity 0.4.16;

interface ERC20 { function transfer(address _to, uint256 _value) public returns (bool); }

contract TokenTransfer { function transferToken(address _tokenAddress, address _to, uint256 _value) public returns (bool) { // Create an instance of the ERC20 token contract ERC20 token = ERC20(_tokenAddress);

    // Transfer the specified amount of tokens to the specified address
    return token.transfer(_to, _value);
}

}

So basically, I want a transfer function of ERC20 tokens on 0.4.16, but I want to make it so that you can specify which token you want to transfer to another address, but everytime I try to send tokens, there's an error, I think it's because the "msg.sender" has to approve the tokens, but idk, this is the code, if you want to review it:

pragma solidity 0.4.16;

interface ERC20 {
    function transfer(address _to, uint256 _value) public returns (bool);
}

contract TokenTransfer {
    function transferToken(address _tokenAddress, address _to, uint256 _value) public returns (bool) {
        // Create an instance of the ERC20 token contract
        ERC20 token = ERC20(_tokenAddress);

        // Transfer the specified amount of tokens to the specified address
        return token.transfer(_to, _value);
    }
}
Source Link

I have a problem using a transfer function in my smart contract solidity 0.4.16

So basically, I want a transfer function of ERC20 tokens on 0.4.16, but I want to make it so that you can specify which token you want to transfer to another address, but everytime I try to send tokens, there's an error, I think it's because the "msg.sender" has to approve the tokens, but idk, this is the code, if you want to review it:

pragma solidity 0.4.16;

interface ERC20 { function transfer(address _to, uint256 _value) public returns (bool); }

contract TokenTransfer { function transferToken(address _tokenAddress, address _to, uint256 _value) public returns (bool) { // Create an instance of the ERC20 token contract ERC20 token = ERC20(_tokenAddress);

    // Transfer the specified amount of tokens to the specified address
    return token.transfer(_to, _value);
}

}