Skip to content

Instantly share code, notes, and snippets.

@viraj124
Created November 12, 2020 10:46
Show Gist options
  • Save viraj124/860568f8652d1799037fc3e285ab0149 to your computer and use it in GitHub Desktop.
Save viraj124/860568f8652d1799037fc3e285ab0149 to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.0;
// very simple version of the wallet contract
contract Wallet {
// this doesn't have a authentication layer since it is an example ideally which ever user is the owner of this wallet can only call this method
function execute(address _target, bytes memory _data)
public
payable
returns (bytes32 response)
{
require(_target != address(0));
// call contract in current context
assembly {
let succeeded := delegatecall(sub(gas(), 5000), _target, add(_data, 0x20), mload(_data), 0, 32)
response := mload(0) // load delegatecall output
switch iszero(succeeded)
case 1 {
// throw if delegatecall failed
revert(0, 0)
}
}
}
receive() external payable {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment