You can do this by creating a contract and having the contract interact with the various token contracts.
One method would be to create your contract, then transfer ownership of your balance on each token to the contract. Untested example (for illustrative purposes only, don't use this as is):
pragma solidity ^0.4.6;
contract ERC20API {
function transfer(address _to, uint256 _value) returns (bool success);
}
contract ProxyContract {
address owner;
function ProxyContract() {
owner = msg.sender;
}
// Simple transfer function, just wraps the normal transfer
function transfer(address token, address _to, uint256 _value) {
if (owner != msg.sender) throw;
ERC20API(token).transfer(_to, _value);
}
// The same as the simple transfer function
// But for multiple transfer instructions
function transferBulk(address[] tokens, address[] _tos, uint256[] _values) {
if (owner != msg.sender) throw;
for(uint256 i=0; i<tokens.length; i++) {
// If one fails, revert the tx, including previous transfers
if (!ERC20API(tokens[i]).transfer(_tos[i], _values[i])) throw;
}
}
}
Another method would be to leave the ownership of the tokens under your own account, and call approve()
against each token to give your proxy contract permission to move them. Then where the above code calls transfer(_to, _value)
in the proxy contract, you'd instead call transferFrom(msg.sender, _to, _value)
.
If A is an external owned account and you want to transfer tokens then you have two options:
- Make tokens transfer: you need to pay for the transfer transaction.
- Approve a third party for the transfer: you need to pay for the approve transaction.
If A is a contract then it doesn't need to have a non zero balance, since the user executing the contract will be paying for the transaction.
Best Answer
Only from the smart contract based wallets that are designed for this. ERC-20 tokens on normal Ethereum accounts cannot do this.