0

I have implemented transactions using ETH, however, I want to exchange tokens between accounts. Here is my code

var postData = {"jsonrpc":"2.0","method":"eth_sendTransaction","params": [{"from":"0x52f273a06a420453aa5b33c4f175395c9a1fddd8", "to": data.ethAddress, "value": 1e18}], "id":1}
    var url = 'http://localhost:8545/'
    var options = {
    method: 'post',
    body: postData,
    json: true,
    url: url
    }
    request(options, function (err, res, body) {
    if (err) {
        console.error('error posting json: ', err)
        throw err
    }
    var headers = res.headers
    var statusCode = res.statusCode
    console.log('headers: ', headers)
    console.log('statusCode: ', statusCode)
    console.log('body: ', body)
    })

This is completing the transaction with 1 ETH being transferred between accounts. However, I want to setup this same action but with my custom token as the currency, not ETH. Any help would be greatly appreciated. Thanks

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Stuart G
  • 187
  • 1
  • 9
  • I did not get the question.. Do you want to send the currency and the value? – Assil Aug 03 '17 at 20:32
  • Essentially I need to do this same thing but with my own token that I created on my localhost 8545 . I deployed the contract I see it in my metamask, and I can transfer it via Metamask, but I want to do it programmatically like how I sent the ETH above – Stuart G Aug 03 '17 at 21:22

2 Answers2

0

I am not sure if that is what you need... You can create a class or two either in C# or in JavaScript to reflect all your properties.

var whatever= {};
whatever.jsonrpc="2.0";
whatever.id=1;
whatever.method="eth_sendTransaction";
whatever.params= [];
whatever.params[0].from="0x52f273a06a420453aa5b33c4f175395c9a1fddd8";
whatever.params[0].to=data.ethAddress;
whatever.params[0].value=1e18;
whatever.params[0].currency="xxx";

etc

Assil
  • 572
  • 6
  • 21
0

I understand that you want to send your token (currency) among different accounts. So, I imagine that you have created your own token and that you have developed your code (your Smart Contract).

  • If not, you should create it.

Then, you should deploy your code and start using it.

You have a tutorial about it here.

Urko
  • 1,479
  • 1
  • 14
  • 20