假设这里是用户A和smartcontract和C。A没有令牌,只有很少的ETH用于gas,但是B有足够的令牌(Erc20)。
这逻辑有可能吗?如果没有,我怎么能做到呢?请纠正我。
发布于 2019-05-23 05:28:27
这里有一些代码可以这样做:
contract C {
ERC20 token = ERC20(0x...);
address ownerOfFoo;
function buyFoo(address owner) external {
require(ownerOfFoo == address(0), "already owned");
require(token.transferFrom(msg.sender, address(this), 1000), "foo costs 1,000 token units");
ownerOfFoo = owner;
}
}
contract B {
ERC20 token = ERC20(0x...);
C c = C(0x...);
function helpMeBuyFoo() external {
// probably you want to allow only A to do this?
// require(...);
token.approve(c, 1000); // tokens will come from B
c.buyFoo(msg.sender); // tell C who should get the service
}
}https://ethereum.stackexchange.com/questions/71026
复制相似问题