Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user

how How to use erc20 transfer in another contract in remix ethereum using metamask?

iI read a lot of documentation in here and another web pages, iI have a question and iI so tried to solved but nothing works for me.

iI am using this example : https://forum.openzeppelin.com/t/example-on-how-to-use-erc20-token-in-another-contract/1682this example.

WorksIt works fine with truffle, but iI don't know what iI need to do to make this workswork fine using metamask.

The problem is the next  :

  • Create a ERC20 Token // works
  • Import the IRC20 Token Contract to Another Contract Named "TokenReceiver" // iI think iI do correctly, iI only copy and paste to test in remix ethereum.
  • Deploy  , Use doStuff function into Thethe new Contract "TokenReceiver" // Error here

Error Says The error says:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? gas required exceeds allowance (10000000) or always failing transaction

The code is the same  :

pragma solidity ^0.5.0;

import "./IERC20.sol";

/**
 * @title TokenReceiver
 * @dev Very simple example of a contract receiving ERC20 tokens.
 */
contract TokenReceiver {

    IERC20 private _token;

    event DoneStuff(address from);

    /**
     * @dev Constructor sets token that can be received
     */
    constructor (IERC20 token) public {
        _token = token;
    }

    /**
     * @dev Do stuff, requires tokens
     */
    function doStuff() external {
        
        address from = msg.sender;

        _token.transferFrom(from, address(this), 1000);

        emit DoneStuff(from);
        
    }
}

iI read a lot but iI really know iI am doing something wrong but iI don't know what it is  , reading I see that I need to approve the function before using transfer, but nothing works for me, iI am trying do this and the error is the same and i dontI don't see the approve window with metamask  :

function doStuff() external {
    
    address from = msg.sender;
    
    _token.approve(from,1000); // i trying adding this line

    _token.transferFrom(from, address(this), 1000);

    emit DoneStuff(from);
    
}

Somebody Helphelp me pleasee please, it is hard tofor me to understand whatswhat's happening but iI really wannawant to know what iI am doing wrong :(.

how to use erc20 transfer in another contract in remix ethereum using metamask?

i read a lot of documentation in here and another web pages, i have a question and i so tried to solved but nothing works for me.

i am using this example : https://forum.openzeppelin.com/t/example-on-how-to-use-erc20-token-in-another-contract/1682

Works fine with truffle, but i don't know what i need to do to this works fine using metamask

The problem is the next  :

  • Create a ERC20 Token // works
  • Import the IRC20 Token Contract to Another Contract Named "TokenReceiver" // i think i do correctly, i only copy and paste to test in remix ethereum.
  • Deploy  , Use doStuff function into The new Contract "TokenReceiver" // Error here

Error Says :

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? gas required exceeds allowance (10000000) or always failing transaction

The code is the same  :

pragma solidity ^0.5.0;

import "./IERC20.sol";

/**
 * @title TokenReceiver
 * @dev Very simple example of a contract receiving ERC20 tokens.
 */
contract TokenReceiver {

    IERC20 private _token;

    event DoneStuff(address from);

    /**
     * @dev Constructor sets token that can be received
     */
    constructor (IERC20 token) public {
        _token = token;
    }

    /**
     * @dev Do stuff, requires tokens
     */
    function doStuff() external {
        
        address from = msg.sender;

        _token.transferFrom(from, address(this), 1000);

        emit DoneStuff(from);
        
    }
}

i read a lot but i really know i am doing something wrong but i don't know what it is  , reading I see that I need to approve the function before using transfer, but nothing works for me, i trying do this and the error is the same and i dont see the approve window with metamask  :

function doStuff() external {
    
    address from = msg.sender;
    
    _token.approve(from,1000); // i trying adding this line

    _token.transferFrom(from, address(this), 1000);

    emit DoneStuff(from);
    
}

Somebody Help me pleasee , is hard to me understand whats happening but i really wanna know what i doing wrong :(

How to use erc20 transfer in another contract in remix ethereum using metamask?

I read a lot of documentation in here and another web pages, I have a question and I so tried to solved but nothing works for me.

I am using this example.

It works fine with truffle, but I don't know what I need to do to make this work fine using metamask.

The problem is the next:

  • Create a ERC20 Token // works
  • Import the IRC20 Token Contract to Another Contract Named "TokenReceiver" // I think I do correctly, I only copy and paste to test in remix ethereum.
  • Deploy, Use doStuff function into the new Contract "TokenReceiver" // Error here

The error says:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? gas required exceeds allowance (10000000) or always failing transaction

The code is the same:

pragma solidity ^0.5.0;

import "./IERC20.sol";

/**
 * @title TokenReceiver
 * @dev Very simple example of a contract receiving ERC20 tokens.
 */
contract TokenReceiver {

    IERC20 private _token;

    event DoneStuff(address from);

    /**
     * @dev Constructor sets token that can be received
     */
    constructor (IERC20 token) public {
        _token = token;
    }

    /**
     * @dev Do stuff, requires tokens
     */
    function doStuff() external {
        
        address from = msg.sender;

        _token.transferFrom(from, address(this), 1000);

        emit DoneStuff(from);
        
    }
}

I read a lot but I really know I am doing something wrong but I don't know what it is, reading I see that I need to approve the function before using transfer, but nothing works for me, I am trying do this and the error is the same and I don't see the approve window with metamask:

function doStuff() external {
    
    address from = msg.sender;
    
    _token.approve(from,1000); // i trying adding this line

    _token.transferFrom(from, address(this), 1000);

    emit DoneStuff(from);
    
}

Somebody help me please, it is hard for me to understand what's happening but I really want to know what I am doing wrong.

edited body
Source Link

i read a lot of documentation in here and another web pages, i have a question and i so tried to solved but nothing works for me.

i am using this example : https://forum.openzeppelin.com/t/example-on-how-to-use-erc20-token-in-another-contract/1682

Works fine with truffle, but i don't know what i need to do to this works fine using metamask

The problem is the next :

  • Create a ERC20 Token // works
  • Import the ERC20IRC20 Token Contract to Another Contract Named "TokenReceiver" // i think i do correctly, i only copy and paste to test in remix ethereum.
  • Deploy , Use doStuff function into The new Contract "TokenReceiver" // Error here

Error Says :

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? gas required exceeds allowance (10000000) or always failing transaction

The code is the same :

pragma solidity ^0.5.0;

import "./IERC20.sol";

/**
 * @title TokenReceiver
 * @dev Very simple example of a contract receiving ERC20 tokens.
 */
contract TokenReceiver {

    IERC20 private _token;

    event DoneStuff(address from);

    /**
     * @dev Constructor sets token that can be received
     */
    constructor (IERC20 token) public {
        _token = token;
    }

    /**
     * @dev Do stuff, requires tokens
     */
    function doStuff() external {
        
        address from = msg.sender;

        _token.transferFrom(from, address(this), 1000);

        emit DoneStuff(from);
        
    }
}

i read a lot but i really know i am doing something wrong but i don't know what it is , reading I see that I need to approve the function before using transfer, but nothing works for me, i trying do this and the error is the same and i dont see the approve window with metamask :

function doStuff() external {
    
    address from = msg.sender;
    
    _token.approve(from,1000); // i trying adding this line

    _token.transferFrom(from, address(this), 1000);

    emit DoneStuff(from);
    
}

Somebody Help me pleasee , is hard to me understand whats happening but i really wanna know what i doing wrong :(

i read a lot of documentation in here and another web pages, i have a question and i so tried to solved but nothing works for me.

i am using this example : https://forum.openzeppelin.com/t/example-on-how-to-use-erc20-token-in-another-contract/1682

Works fine with truffle, but i don't know what i need to do to this works fine using metamask

The problem is the next :

  • Create a ERC20 Token // works
  • Import the ERC20 Token Contract to Another Contract Named "TokenReceiver" // i think i do correctly, i only copy and paste to test in remix ethereum.
  • Deploy , Use doStuff function into The new Contract "TokenReceiver" // Error here

Error Says :

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? gas required exceeds allowance (10000000) or always failing transaction

The code is the same :

pragma solidity ^0.5.0;

import "./IERC20.sol";

/**
 * @title TokenReceiver
 * @dev Very simple example of a contract receiving ERC20 tokens.
 */
contract TokenReceiver {

    IERC20 private _token;

    event DoneStuff(address from);

    /**
     * @dev Constructor sets token that can be received
     */
    constructor (IERC20 token) public {
        _token = token;
    }

    /**
     * @dev Do stuff, requires tokens
     */
    function doStuff() external {
        
        address from = msg.sender;

        _token.transferFrom(from, address(this), 1000);

        emit DoneStuff(from);
        
    }
}

i read a lot but i really know i am doing something wrong but i don't know what it is , reading I see that I need to approve the function before using transfer, but nothing works for me, i trying do this and the error is the same and i dont see the approve window with metamask :

function doStuff() external {
    
    address from = msg.sender;
    
    _token.approve(from,1000); // i trying adding this line

    _token.transferFrom(from, address(this), 1000);

    emit DoneStuff(from);
    
}

Somebody Help me pleasee , is hard to me understand whats happening but i really wanna know what i doing wrong :(

i read a lot of documentation in here and another web pages, i have a question and i so tried to solved but nothing works for me.

i am using this example : https://forum.openzeppelin.com/t/example-on-how-to-use-erc20-token-in-another-contract/1682

Works fine with truffle, but i don't know what i need to do to this works fine using metamask

The problem is the next :

  • Create a ERC20 Token // works
  • Import the IRC20 Token Contract to Another Contract Named "TokenReceiver" // i think i do correctly, i only copy and paste to test in remix ethereum.
  • Deploy , Use doStuff function into The new Contract "TokenReceiver" // Error here

Error Says :

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? gas required exceeds allowance (10000000) or always failing transaction

The code is the same :

pragma solidity ^0.5.0;

import "./IERC20.sol";

/**
 * @title TokenReceiver
 * @dev Very simple example of a contract receiving ERC20 tokens.
 */
contract TokenReceiver {

    IERC20 private _token;

    event DoneStuff(address from);

    /**
     * @dev Constructor sets token that can be received
     */
    constructor (IERC20 token) public {
        _token = token;
    }

    /**
     * @dev Do stuff, requires tokens
     */
    function doStuff() external {
        
        address from = msg.sender;

        _token.transferFrom(from, address(this), 1000);

        emit DoneStuff(from);
        
    }
}

i read a lot but i really know i am doing something wrong but i don't know what it is , reading I see that I need to approve the function before using transfer, but nothing works for me, i trying do this and the error is the same and i dont see the approve window with metamask :

function doStuff() external {
    
    address from = msg.sender;
    
    _token.approve(from,1000); // i trying adding this line

    _token.transferFrom(from, address(this), 1000);

    emit DoneStuff(from);
    
}

Somebody Help me pleasee , is hard to me understand whats happening but i really wanna know what i doing wrong :(

Source Link

how to use erc20 transfer in another contract in remix ethereum using metamask?

i read a lot of documentation in here and another web pages, i have a question and i so tried to solved but nothing works for me.

i am using this example : https://forum.openzeppelin.com/t/example-on-how-to-use-erc20-token-in-another-contract/1682

Works fine with truffle, but i don't know what i need to do to this works fine using metamask

The problem is the next :

  • Create a ERC20 Token // works
  • Import the ERC20 Token Contract to Another Contract Named "TokenReceiver" // i think i do correctly, i only copy and paste to test in remix ethereum.
  • Deploy , Use doStuff function into The new Contract "TokenReceiver" // Error here

Error Says :

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? gas required exceeds allowance (10000000) or always failing transaction

The code is the same :

pragma solidity ^0.5.0;

import "./IERC20.sol";

/**
 * @title TokenReceiver
 * @dev Very simple example of a contract receiving ERC20 tokens.
 */
contract TokenReceiver {

    IERC20 private _token;

    event DoneStuff(address from);

    /**
     * @dev Constructor sets token that can be received
     */
    constructor (IERC20 token) public {
        _token = token;
    }

    /**
     * @dev Do stuff, requires tokens
     */
    function doStuff() external {
        
        address from = msg.sender;

        _token.transferFrom(from, address(this), 1000);

        emit DoneStuff(from);
        
    }
}

i read a lot but i really know i am doing something wrong but i don't know what it is , reading I see that I need to approve the function before using transfer, but nothing works for me, i trying do this and the error is the same and i dont see the approve window with metamask :

function doStuff() external {
    
    address from = msg.sender;
    
    _token.approve(from,1000); // i trying adding this line

    _token.transferFrom(from, address(this), 1000);

    emit DoneStuff(from);
    
}

Somebody Help me pleasee , is hard to me understand whats happening but i really wanna know what i doing wrong :(