Last active
December 17, 2019 07:50
-
-
Save w3kim/d32afcfeb93ca1c7b7dc734c6100e55e 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
@Test | |
public void VTTest() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, IOException { | |
BigInteger privKey = Keys.createEcKeyPair().getPrivateKey(); | |
KlayCredentials credential = KlayCredentials.create(privKey.toString(16)); // newly created credential | |
KlayTransactionReceipt.TransactionReceipt receipt; | |
receipt = transfer(senderCredential, credential, Convert.toPeb("0.5", Convert.Unit.KLAY).toBigInteger()); | |
Assert.assertNotNull(receipt); | |
receipt = transfer(credential, recipientCredential, Convert.toPeb("0.3", Convert.Unit.KLAY).toBigInteger()); | |
Assert.assertNotNull(receipt); | |
} | |
private KlayTransactionReceipt.TransactionReceipt transfer(KlayCredentials from, KlayCredentials to, BigInteger value) throws IOException { | |
log.info("transfer {} KLAY [{} -> {}]", value.toString(), from.getAddress(), to.getAddress()); | |
BigInteger nonce = caver.klay().getTransactionCount(from.getAddress(), BLK_PARAM).send().getValue(); | |
TxTypeValueTransfer tx = TxTypeValueTransfer.createTransaction( | |
nonce, | |
GAS_PRICE, | |
GAS_LIMIT, | |
to.getAddress(), | |
value, | |
from.getAddress() | |
); | |
TransactionManager manager = new TransactionManager.Builder(caver, from) | |
.setTransactionReceiptProcessor(new PollingTransactionReceiptProcessor(caver, 1000, 10)) | |
.setChaindId(CHAIN_ID) | |
.build(); | |
KlayTransactionReceipt.TransactionReceipt receipt = manager.executeTransaction(tx); | |
log.info("{}", receipt.toString()); | |
return receipt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment