Reputation: 75
I would like to know how i set the origin from the transfer...
I have this contract (my actual contract is bigger than that, but that is the part that matters...):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Testing{
address payable public manager;
constructor(){
manager =payable(msg.sender);
}
function getMoneyFromManager(uint quantity) public payable{
//someone different from manager should recieve money from manager
//something like: msg.sender.transfer(quantity) => FROM MANAGER
}
}
But i don't know how to set the origin from the transfer. Any ideas?
Upvotes: 0
Views: 1731
Reputation: 1062
so you want to transfer ETH/BNB (native blockchain's crypto) fomr manager to user through the contract, but i'm sorry, you can't is impossible take native crypto from an address and transfer it to another through smart contracts
but anyway there are 2 solutions:
keep native crypto inside the contract and not inside the manager wallet, so when you call that function, the contract will transfer native crypto from it self address(this)
to the user
use wrapped token instead, with tokens you can do what you are trying to do. The wallet manager must approve within the token contract your actual contract to spend his token
then the contract will be like:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
IMPORT "@openzeppelin/contracts/tokens/ERC20/IERC20.sol";
contract Testing{
address public manager;
IERC20 wETH;
constructor(IERC20 _wETH){
manager =msg.sender;
wETH = _wETH;
}
function getMoneyFromManager(uint quantity) public payable{
//msg.sender will receive money from manager
wETH.transferFrom(manager, msg.sender, quantity)
}
}
NOTE:
Make getMoneyFromManager
function onlyOwner, otherwise everyone will be able to get money
Upvotes: 2