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
package com.example; | |
import com.klaytn.caver.Caver; | |
import com.klaytn.caver.crypto.KlayCredentials; | |
import com.klaytn.caver.methods.response.KlayLogs; | |
import com.klaytn.caver.methods.response.KlayTransactionReceipt; | |
import com.klaytn.caver.tx.SmartContract; | |
import com.klaytn.caver.tx.manager.TransactionManager; | |
import java.math.BigInteger; | |
import java.util.ArrayList; |
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
pragma solidity ^0.4.24; | |
/** | |
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include | |
* the optional functions; to access them see `ERC20Detailed`. | |
*/ | |
interface IERC20 { | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address account) external view returns (uint256); |
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
package com.klaytn.example.caver; | |
import com.klaytn.caver.Caver; | |
import com.klaytn.caver.crypto.KlayCredentials; | |
import com.klaytn.caver.fee.FeePayerManager; | |
import com.klaytn.caver.methods.response.KlayTransactionReceipt; | |
import com.klaytn.caver.tx.manager.PollingTransactionReceiptProcessor; | |
import com.klaytn.caver.tx.type.TxTypeFeeDelegatedValueTransfer; | |
import com.klaytn.caver.utils.ChainId; | |
import org.junit.Assert; |
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
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, |
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); |
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
const Caver = require('caver-js') | |
const caver = new Caver('https://api.baobab.klaytn.net:8651') | |
const originalKey = 'original_key'; | |
const originalAccount = caver.klay.accounts.wallet.add(originalKey); | |
const address = originalAccount.address; | |
const acct1 = caver.klay.accounts.privateKeyToAccount('key1'); | |
const acct2 = caver.klay.accounts.privateKeyToAccount('key2'); | |
const acct3 = caver.klay.accounts.privateKeyToAccount('key3'); |
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
const Caver = require('caver-js'); | |
const caver = new Caver('https://api.baobab.klaytn.net:8651'); | |
const address = '0x{address_of_account_you_wish_to_update}'; | |
const oldPrivateKey = '0x{effective_private_key_bound_to_the_address_above}'; | |
const newPrivateKey = caver.klay.accounts.create().privateKey; // new private key to update | |
// use createAccountForUpdate | |
const accountForUpdate = caver.klay.accounts.createAccountForUpdate(address, newPrivateKey); | |
console.log('>>> about to configure ACCOUNT(address=', address, ') with the following key:', newPrivateKey) |
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
const Caver = require('caver-js'); | |
const caver = new Caver('https://api.baobab.klaytn.net:8651/'); | |
const acct = caver.klay.accounts.privateKeyToAccount('your_private_key') | |
caver.klay.accounts.wallet.add(acct) | |
// Refer to count.sol for Solidity code | |
const COUNT_BYTECODE = { | |
"linkReferences": {}, | |
"object": "60806040526000805534801561001457600080fd5b5060e8806100236000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c806306661abd14604157806342cbb15c14605d578063d14e62b8146079575b600080fd5b604760a4565b6040518082815260200191505060405180910390f35b606360aa565b6040518082815260200191505060405180910390f35b60a260048036036020811015608d57600080fd5b810190808035906020019092919050505060b2565b005b60005481565b600043905090565b806000819055505056fea165627a7a7230582087453d981a85f80c5262508e1fe5abe94dc38b1167c49b6e3477b74293e9e7000029", |
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
const Caver = require('caver-js') | |
const caver = new Caver('https://api.baobab.klaytn.net:8651') | |
const sender = caver.klay.accounts.wallet.add('your_private_key'); | |
const recipient = 'recipient_address'; | |
const x = async () => { | |
const account = await caver.klay.getAccount(sender.address); | |
const startingNonce = account.account.nonce; | |
console.log(startingNonce); |
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
const Caver = require('caver-js'); | |
const caver = new Caver('https://api.baobab.klaytn.net:8651/'); | |
caver.klay.accounts.wallet.create(1); | |
const sender = caver.klay.accounts.wallet[0]; | |
// if there is only one key bound to an address where last160bits(keccak(key)) === address, then the key can function as payer key | |
const payer = caver.klay.accounts.wallet.add('0x42605fa83957d67ca8e5c843820c72037ee5dbc6b0b2d14f9d4bd5de41b446de'); | |
// an arbitrary contract is used | |
async function run() { |
NewerOlder