Skip to content

Instantly share code, notes, and snippets.

@adyliu
Created September 28, 2018 09:29
Show Gist options
  • Save adyliu/492503b94d0306371298f24e15481da4 to your computer and use it in GitHub Desktop.
Save adyliu/492503b94d0306371298f24e15481da4 to your computer and use it in GitHub Desktop.
sign transaction offline for eos transfer
package eos.sample;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import org.apache.log4j.BasicConfigurator;
import io.jafka.jeos.EosApi;
import io.jafka.jeos.EosApiFactory;
import io.jafka.jeos.LocalApi;
import io.jafka.jeos.core.common.SignArg;
import io.jafka.jeos.core.common.transaction.PackedTransaction;
import io.jafka.jeos.core.common.transaction.SignedPackedTransaction;
import io.jafka.jeos.core.request.chain.transaction.PushTransactionRequest;
import io.jafka.jeos.core.response.chain.transaction.PushedTransaction;
/**
*
* @author adyliu ([email protected])
* @since Sep 28, 2018
*/
public class OfflineEOSTransfer {
public static void main(String[] args) throws Exception{
// --- get the current state of blockchain
EosApi eosApi = EosApiFactory.create("http://jungle.cryptolions.io:18888");
SignArg arg = eosApi.getSignArg(120);
System.out.println(eosApi.getObjectMapper().writeValueAsString(arg));
// --- sign the transation of token tansfer
String privateKey = "5JTKZ------";//replace the real private key
String from = "shijiebangmm";
String to = "womenshi1111";
String quantity = "0.2345 EOS";
String memo = "sent by eos sdk (https://github.com/adyliu/jeos";
LocalApi localApi = EosApiFactory.createLocalApi();
PushTransactionRequest req = localApi.transfer(arg, privateKey, from, to, quantity, memo);
System.out.println(localApi.getObjectMapper().writeValueAsString(req));
// --- push the signed-transaction to the blockchain
PushedTransaction pts = eosApi.pushTransaction(req);
System.out.println(localApi.getObjectMapper().writeValueAsString(pts));
}
}
@BhumikaB
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment