Skip to content

Instantly share code, notes, and snippets.

Last active April 5, 2020 14:16
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Klaytn: deploying smart contract with fee delegation
const Caver = require('caver-js');
const caver = new Caver('');
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({
from: sender.address,
data: "0x60806040526000805534801561001457600080fd5b5060e8806100236000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c806306661abd14604157806342cbb15c14605d578063d14e62b8146079575b600080fd5b604760a4565b6040518082815260200191505060405180910390f35b606360aa565b6040518082815260200191505060405180910390f35b60a260048036036020811015608d57600080fd5b810190808035906020019092919050505060b2565b005b60005481565b600043905090565b806000819055505056fea165627a7a7230582087453d981a85f80c5262508e1fe5abe94dc38b1167c49b6e3477b74293e9e7000029",
gas: '3000000',
value: 0,
}, sender.privateKey);
// signed raw transaction
console.log("Raw TX:\n", senderRawTransaction);
// send fee delegated transaction with fee payer information
senderRawTransaction: senderRawTransaction,
feePayer: payer.address
.on('transactionHash', function (hash) {
console.log(">>> tx_hash for deploy =", hash);
.on('receipt', function (receipt) {
console.log(">>> receipt arrived: ", receipt);
.on('error', function (err) {
console.error(">>> error: ", err);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment