Delegatecall in Transactions – Usage and Best Practices

assemblydelegatecallsoliditytransactions

I'm interested in techniques to perform multiple sends/contract calls inside of a single transaction but with the EOA that originates the transaction still being the sender for all operations (not a wallet contract or other non-EOA account).

Is it possible in either solidity or EVM assembly to have a transaction (as opposed to an inter-contract call) use delegatecall?
It would be great if an EOA could claim the operations of a library contract as its own while retaining the EOA's msg.sender and msg.value.

Example flow:

My externally owned secp256k1 account delegatecalls a contract library X whose solidity code a) calls some other contract Y to check whether a certain variable is equal to a certain value, and then b) calls the method of a different contract Z if and only if it is, sending along 1 ETH.

Both the call to Y to check the variable in a), and the call to the method of Z in b) should have msg.sender being my externally owned secp256k1 account, and the outward send/call in b) should spend the balance of my externally owned secp256k1 account. Neither X nor Y should think anything different has happened than just that they were directly called by my EOA.

Best Answer

DELEGATECALL is an instruction interpreted by EVM. So to execute DELEGATECALL you have to have a program (contract) that gets executed on EVM.

DELEGATECALL takes six operands, one of them is the address of the calee. So it can only call deployed contracts. Note that so called library is just a special contract which operations are called with DELEGATECALL.

So to answer your question directly as I understand it: No - it is not possible to execute arbitrary code from an external account.

What you can do though is you can create a contract that implements the logic as you want it and uses DELEGATECALL to preserve sender and value when calling other contracts.