I am trying to send Plasma tokens in testnet but unfortunately misunderstand how I should create transaction properly.
I try to create tx like this:
String privateKeyString = "xxx";
BigInteger bigInteger = new BigInteger(privateKeyString, 16);
ECKey ecKey = ECKey.fromPrivate(bigInteger);
String plasmaContrtactAddress = "0x95D7321EdCe519419ba1DbC60A89bAfbF55EAC0D";
Transaction ethTx = new Transaction(
nonce,
gasPrice,
gasLimit,
plasmaContrtactAddress,
value,
data);
ethTx.sign(ecKey)
But how I should to create byte[] data properly? Here is json abi interface for plasma:
[{"constant":true,"inputs":[],"name":"message","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ViewerStatus","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ViewerValue","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenRateEther","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"Login","type":"string"}],"name":"registrationFromLogin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"MainAccount","type":"address"},{"name":"ActiveAliasAccount","type":"bool"},{"name":"ActiveMainAccount","type":"bool"},{"name":"PromilleDeposit","type":"uint256"},{"name":"DeleteMainAccount","type":"bool"}],"name":"setupAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"NewPIN","type":"uint256"}],"name":"setupAccountPIN","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"deleteLogin","type":"string"},{"name":"newLogin","type":"string"}],"name":"setupLoginVipAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"MainAccount","type":"address"}],"name":"setupAliasAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"Account","type":"address"},{"name":"Freezen","type":"bool"}],"name":"frozenSubAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"Account","type":"address"}],"name":"buyVipStatusPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"buyTokenPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"toTransferETHER","type":"address"},{"name":"microToken","type":"uint256"},{"name":"SellDeposit","type":"bool"}],"name":"sellToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"login","type":"string"},{"name":"password","type":"string"}],"name":"depositaryPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"Account","type":"address"},{"name":"microToken","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"Login","type":"string"},{"name":"PIN","type":"uint256"}],"name":"transferFromLoginPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"Login","type":"string"}],"name":"transferToLoginPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"microToken","type":"uint256"}],"name":"returnDepositToBalance","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"SubAccount","type":"address"},{"name":"PIN","type":"uint256"}],"name":"transferProtectPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"PIN","type":"uint256"}],"name":"unblockTransferProtectPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"SubAccount","type":"address"},{"name":"pinSubAccount","type":"uint256"},{"name":"promilleRefund","type":"uint256"}],"name":"transferRefundSubAccountPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"MainAccount","type":"address"},{"name":"pinMainAccount","type":"uint256"},{"name":"SubAccount","type":"address"},{"name":"pinSubAccount","type":"uint256"},{"name":"promilleReferee","type":"uint256"}],"name":"refereeTransferProtect","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"VipAccount","type":"bool"},{"name":"ActiveAliasAccount","type":"bool"},{"name":"ActiveMainAccount","type":"bool"},{"name":"MainAccount","type":"address"},{"name":"MyReferralAccount","type":"address"}],"name":"MyAccountStatus","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"Deposit","type":"bool"},{"name":"PromilleDeposit","type":"bool"},{"name":"ZoneToken","type":"bool"}],"name":"MyAccountValue","outputs":[{"name":"value","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"myMessage","type":"string"}],"name":"advertisingPay","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"burnToken","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"microToken","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"Message","type":"string"}],"name":"Advertising","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"microToken","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"PriceVipAccountMicroEther","type":"uint256"},{"indexed":false,"name":"TransferTokensFeeInPromille","type":"uint256"},{"indexed":false,"name":"BonusForZone1InPromille","type":"uint256"},{"indexed":false,"name":"BonusForZone2InPromille","type":"uint256"},{"indexed":false,"name":"BonusForZone3InPromille","type":"uint256"},{"indexed":false,"name":"BonusForZone4InPromille","type":"uint256"},{"indexed":false,"name":"BonusForZone5InPromille","type":"uint256"}],"name":"OptionsContract","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"microETHER","type":"uint256"}],"name":"TokenSellingRate","type":"event"}]
And the receiver's address:
0xEA8e872b51d76D690E4779F9AC403cf18B8460Fe
How can I implement this with ethereumJ library or manualy, whatever?
UPDATED:
First of all - thanks to cleanunicorn for the answer below.
In addition to the code above - my version of the byte[] data for transferring tokens:
public byte[] createTransferData(String addressTo, @NonNull String value) {
String functionSig = "0xa9059cbb"; // transfer
byte[] functionBytes = ByteUtil.hexStringToBytes(functionSig);
byte[] addressSrc = Hex.decode(Numeric.cleanHexPrefix(addressTo));
byte[] emptyBytesAddress = new byte[32 - addressSrc.length];
addressSrc = ByteUtil.merge(emptyBytesAddress, addressSrc);
BigInteger bigInteger = new BigInteger(value);
byte[] valueSrc = ByteUtil.hexStringToBytes(bigInteger.toString(16));
// here we should calculate bytes' count of our hex value
// and if we are out of bounds of the count/32 - we should provide 32 bytes extra
int additionalEmptyBytes = 32 - (valueSrc.length - (valueSrc.length / 32) * 32);
if (additionalEmptyBytes != 0) {
valueSrc = ByteUtil.merge(new byte[additionalEmptyBytes], valueSrc);
}
return ByteUtil.merge(functionBytes, addressSrc, valueSrc);
}
Here is ByteUtils class.
If someone know how to implement it via ethereumJ or maybe faster - please provide your answer.