Skip to content

Instantly share code, notes, and snippets.

@andreafspeziale
Created December 18, 2019 09:55
Show Gist options
  • Save andreafspeziale/2a888ca3fc5f32c06d26d2c64cf2e2ed to your computer and use it in GitHub Desktop.
Save andreafspeziale/2a888ca3fc5f32c06d26d2c64cf2e2ed to your computer and use it in GitHub Desktop.
Get the sender/signer from the first argument of the transaction data field
/**
 * @dev Return the first param of the meta tx data field which must be an address.
 * E.g: in transferFrom(sender, to, amount) sender address is returned.
 * @param dataField The meta transactions data field.
 */
function getAddressFromData(bytes memory dataField)
  public
  pure
  returns (address)
{
  address sender;
  // solium-disable-next-line security/no-inline-assembly
  assembly {
      sender := mload(add(dataField, 36))
  }
  return sender;
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment