myetherwallet allows you to send tokens without asking anything
Most tokens are implemented using ERC20 standard, and it clearly defines the function format for transferring tokens. So only the other parts of transaction are required.
Should I use the private key of my ethereum address to sign this transaction? or its another private key like the contract one
Contract does not have any private key. If your account holds any tokens, then those tokens can be transferred by that account if that account submits a signed txn to transfer tokens.
how come I can't do the same programatically? What am I missing?
You can do it programatically. Token transfer function resides inside the contract. You can call that function from senders account. And sender's tokens would be transferred. You may find code to achieve this at How to send ERC20 token using Web3 API?
var count = web3.eth.getTransactionCount("0x26...");
var abiArray = JSON.parse(fs.readFileSync('mycoin.json', 'utf-8'));
var contractAddress = "0x8...";
var contract = web3.eth.contract(abiArray).at(contractAddress);
var rawTransaction = {
"from": "0x26...",
"nonce": web3.toHex(count),
"gasPrice": "0x04e3b29200",
"gasLimit": "0x7458",
"to": contractAddress,
"value": "0x0",
"data": contract.transfer.getData("0xCb...", 10, {from: "0x26..."}),
"chainId": 0x03
};
var privKey = new Buffer('fc3...', 'hex');
var tx = new Tx(rawTransaction);
tx.sign(privKey);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
if (!err)
console.log(hash);
else
console.log(err);
});
It seems I need the ABI, but I would like to avoid using it.
You can use ABI of any ERC20 token, since all ERC20 tokens have that one function that you want to call.
This is not currently possible with the ERC20 standard. There are a few proposals that address this issue from different angles, but none of them is accepted as a standard yet:
- EIP 865 supports
delegatedTransfer
- EIP 965 extends ERC777 with a "Cheque Operator". The use case you asked about is described here.
Both these proposals require changes in the token contract though, so they won't work for already existing ERC20 tokens.
So the obvious solution, unfortunately, is to send just enough ether to the generated addresses to cover the gas costs for moving the tokens out.
If you happen to own significant mining power to produce a block every X hours and you're ready to wait X hours to move those tokens out, you can configure your mining software to include your own zero-fee transactions in your own blocks.
Best Answer
Short answer is no.
Detailed answer here: Ethereum gas explained
I am not aware of your idea, but you can calculate gas and request it back from the contract.