0

I want to create a service to send tokens from different wallets. I already created the ethereum transactions, but I don't get tokens yet.

It seems I need the ABI, but I would like to avoid using it. I've seen that myetherwallet allows you to send tokens without asking anything other than the destination and the gas pretty much.

Some questions:

Should I use the private key of my ethereum address to sign this transaction? or its another private key like the contract one

If myetherwallet allows me to send tokens from one address to another, how come I can't do the same programatically? What am I missing?

Thank you

1

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.

  • Can you please share the whole tutorial of this so that i can implement it from beginning – veeresh kumbar Apr 12 '18 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.