Skip to main content
updates for clarity had contained syntax errors
Source Link
Rolan
  • 135
  • 4

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
      allowed[msg.sender][_spender]sender][spender] = _value;amount;
      emit Approval(msg.sender, _spenderspender, _valueamount);
      return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
      allowed[msg.sender][_spender] = _value;
      emit Approval(msg.sender, _spender, _value);
      return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
      allowed[msg.sender][spender] = amount;
      emit Approval(msg.sender, spender, amount);
      return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

added 53 characters in body
Source Link
Rolan
  • 135
  • 4

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
      allowed[msg.sender][_spender] = _approve_value;
      emit Approval(msg.sender, spender_spender, amount_value);
        return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
      allowed[msg.sender][_spender] = _value;
      emit Approval(msg.sender, _spender, _value);
      return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

deleted 4 characters in body
Source Link
Rolan
  • 135
  • 4

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToRankAddressessendTokenToAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToRankAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

I have a contract that's responsible for distributing an ERC20 token to a list of addresses. In the contract there's a function that simplifies to something like:

function sendTokenToAddresses(uint amount, address[] memory addresses) external onlyOwner() nonReentrant(){
    for(uint i=0;i<addresses.length;i++){           
        erc20Contract.approve(addresses[i], amount);
        erc20Contract.transferFrom(address(this), addresses[i], amount);
    }
}

The approve function for the ERC20 token is fairly standard and looks like this:

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

This function is only meant to be run by the contract owner (set in the constructor). But in testing (truffle) my testing on this function fails because it's trying to pass tokens from the caller (owner) rather than the contract address.

How can I call the approve method on the erc20Contract so that the msg.sender value is the contract address rather than the contract owner address?

Source Link
Rolan
  • 135
  • 4
Loading