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) | |
/* | |
We will use the following contract to demonstrate the use of bytes32: | |
pragma solidity 0.4.24; |
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
// The following example is a modified version of | |
// the one introduced on https://docs.klaytn.com/getting-started/quick-start/check-the-deployment | |
const Caver = require('caver-js'); | |
const caver = new Caver('https://api.baobab.klaytn.net:8651'); // using Baobab testnet | |
const contractAddress = '0x799599e8170f210af2c85187bacd070751cb114a' // pre-deployed contract | |
caver.klay.getCode(contractAddress).then(console.log); |
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('sender_private_key'); | |
const payer = caver.klay.accounts.wallet.add('fee_payer_key', 'target_address'); | |
// an arbitrary contract is used | |
async function run() { | |
// make sure `data` starts with 0x | |
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({ |
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.crpyto.KlayCredentials; | |
import com.klaytn.caver.fee.FeePayerManager; | |
import com.klaytn.caver.methods.response.KlayTransactionReceipt; | |
import com.klaytn.caver.tx.gas.DefaultGasProvider; | |
import com.klaytn.caver.tx.manager.PollingTransactionReceiptProcessor; | |
import com.klaytn.caver.tx.model.ValueTransferTransaction; |
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/'); | |
// getBlock's second parameter is boolean; if true, getBlock returns a block with transaction objects. | |
caver.klay.getBlock(9660831, true).then((resp) => { | |
const { transactions } = resp; | |
const filtered = transactions.filter((e) => { return e['to'] === 'address_you_are_looking_for' }); | |
console.log(filtered); | |
}); |
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() { |
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/'); | |
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 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 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'); |
OlderNewer