Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeERC20: forward revert reasons instead of "low-level call failed" #1805

Closed
AyushKaul opened this issue Jun 20, 2019 · 21 comments
Closed

SafeERC20: forward revert reasons instead of "low-level call failed" #1805

AyushKaul opened this issue Jun 20, 2019 · 21 comments
Labels
question Compilation errors, reverts on transactions, design questions.

Comments

@AyushKaul
Copy link

AyushKaul commented Jun 20, 2019

I'm using the crowdsale contract. I have deployed a detailedERC20 smart contract. When I send the ether to the crowdsale contract it shows me the following error:
SafeERC20: low-level call failed

When I use transfer() externally it works fine.

💻 Environment
Ganache-cli

@AyushKaul AyushKaul changed the title "ByzantiumBlock": 0 SafeERC20: low-level call failed Jun 20, 2019
@Skyge
Copy link
Contributor

Skyge commented Jun 24, 2019

Ohh? Maybe you there is something wrong with the token address you providing.

@AyushKaul
Copy link
Author

Are you talking about the ERC20 contract address?
I deployed the ERC-20 token first, then used the same address in the crowdsale contract. I'm positive that's the same.

@nventuro
Copy link
Contributor

Hello @pushcodeveryday, thanks for reporting this!

Indeed, that error message isn't the best. @frangio and I thought about also including the original revert message, but we didn't get around to doing it yet.

Could you share the code for your crowdsale and token contracts? What function of SafeERC20 are you calling?

@AyushKaul
Copy link
Author

@nventuro I'm using the openzeppelin crowdsale contract:
https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/crowdsale/Crowdsale.sol
I'm simply sending ether to this contract, So buyTokens(msg.sender) is called.
Token again openzeppelin DetailedERC20:
https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC20/ERC20Detailed.sol

@nventuro
Copy link
Contributor

Did you give tokens to the Crowdsale contract? The default buyTokens will call transfer on them, so it the contract has no tokens that call will revert.

@AyushKaul
Copy link
Author

I deployed the crowdsale contract with the address having ERC20 tokens, I also passed the contract address at the time of deploying the crowdsale contract.

@nventuro
Copy link
Contributor

I'm not sure I fully understand your setup, if you have a deployment script, could you share it?

To clarify, what you'd need to do is:

a) Deploy the token contract
b) Deploy the crowdsale contract, passing it the token contract's address
c) Give tokens to the crowdsale contract

@nventuro nventuro added the question Compilation errors, reverts on transactions, design questions. label Jun 27, 2019
@AyushKaul
Copy link
Author

@nventuro , Just to be clear, You are saying that i should transfer erc20 tokens to the crowdsale contract?

@nventuro
Copy link
Contributor

Correct: the base Crowdsale will deliver tokens to buyers by calling transfer. You can read more about it in our crowdsales guide.

@frangio
Copy link
Contributor

frangio commented Jun 28, 2019

We definitely should start forwarding the underlying reason string.

@AyushKaul
Copy link
Author

Okay, I'll try that out.

@pengming273
Copy link

regarding step 3: c) Give tokens to the crowdsale contract, how to implement it?

@abcoathup
Copy link
Contributor

Hi @pengming273

regarding step 3: c) Give tokens to the crowdsale contract, how to implement it?

The OpenZeppelin Contracts tests are great to see how to implement:
You just need to transfer the supply of the token to the crowdsale

await this.token.transfer(this.crowdsale.address, tokenSupply);

If you need more information on how to implement I suggest you post in the Community Forum: https://forum.openzeppelin.com

@AyushKaul
Copy link
Author

@frangio, I agree that the error message is not intuitive. Refactoring the returned errors might be useful in cases like these.

@nventuro
Copy link
Contributor

An issue that came up is that Solidity adds a special marker at the beginning of revert reasons, and this doesn't play nice when re-throwing reverts (i.e. there's some extra bytes at the beginning of the parsed revert reason). Perhaps the marker is being included twice? In any case, this needs some more looking-into.

@AyushKaul
Copy link
Author

I'll also look into it.

@frangio frangio reopened this Nov 12, 2019
@frangio
Copy link
Contributor

frangio commented Nov 12, 2019

Let's leave this issue open. We still think it needs to be fixed. The open PR #1943 is dealing with a similar issue with revert reasons.

@frangio frangio changed the title SafeERC20: low-level call failed SafeERC20: forward revert reasons instead of "low-level call failed" Nov 12, 2019
@AyushKaul
Copy link
Author

okay, but I don't see saferc20 being changed.

@frangio
Copy link
Contributor

frangio commented Nov 13, 2019

Once we've figured how to deal with this in the context of #1943 we can apply the same technique to SafeERC20.

@frangio
Copy link
Contributor

frangio commented Dec 6, 2019

Unfortunately the author of #1943 stopped working on it. Does someone want to pick it up and continue the work?

@frangio
Copy link
Contributor

frangio commented Jul 8, 2020

This was fixed in #2264 and it was released as part of 3.1.0!

@frangio frangio closed this as completed Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Compilation errors, reverts on transactions, design questions.
Projects
None yet
Development

No branches or pull requests

6 participants