Created
July 11, 2017 22:19
-
-
Save tinybike/3e08f7cafa1b36714584436ca4dc609b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var rpc = require("ethrpc"); | |
var tokenContractAddress = "0x..."; // address of ERC-20 token contract | |
var valueToSend = "0x42"; // value to send (in wei, i.e. 1e-18 ether) | |
var sender = "0x..."; // sending address | |
var receiver = "0x..."; // receiving address | |
var privateKey = Buffer.from("...", "hex"); // private key as bytearray (buffer) | |
rpc.connect({ | |
httpAddresses: [], // ethereum node HTTP endpoint | |
wsAddresses: [], // ethereum node websocket endpoint | |
ipcAddresses: [] // ethereum node IPC endpoint | |
}, () => { | |
rpc.packageAndSignRawTransaction({ | |
from: sender, | |
to: tokenContractAddress, | |
method: "transfer", | |
params: [receiver, valueToSend], | |
signature: ["address", "uint256"] | |
}, sender, privateKey, (signedRawTransaction) => { | |
console.log("signed raw transaction:", signedRawTransaction); | |
rpc.sendRawTransaction(signedRawTransaction, (rpcResponse) => { | |
console.log("response from ethereum node:", rpcResponse); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment