I want to build a smart contract which can only be constructed, if there's an amount x of a specific ERC20 token available to spend for this contract.
So either the contract has to be allowed to spend this amount in the name of the creator of the contract or it already has the desired balance itself. I don't think there's really a difference between these 2 options from conceptual perspective but in some way the contract must be able to spend amount x and if amount x is not available for spending than the contract should not be deployed at all. And just for clarification, the amount x would also be passed with the constructor.
Actually i just want to have something like the following which is obviously not really possible:
constructor(uint x, ...) public {
require(
token.transferFrom(msg.sender, this, x)
//...
);
//...
}
Is it possible to achieve this?
It's not really an option to transfer tokens to the address of the contract before it's even deployed i think. Theoretically it could be done this way this since contract addresses are deterministically computed from what i know but i'm really looking for a more handy solution.
Oh, and this ERC20 token is also issued by myself. If it would bring any benfits to extend the token's smart contract, i could do this for sure.
In the end i want to have a contract which can promise to pay out certain participants and i want to have a guarantee from the beginning that this is possible. These certain participants are predetermined as well so imo it would only make sense to have the promised amount x of tokens ready at contract construction.
require()
needs aboolean
as an argument, so make sure thattransferFrom()
returns aboolean
.