Skip to main content

Account Update

sendTransaction (ACCOUNT_UPDATE)


caver.klay.sendTransaction(transactionObject [, callback])

Sends an Account Update transaction to the network.

Parameters

The parameters of sendTransaction are a transaction object and a callback function.

NameTypeDescription
transactionObjectObjectThe transaction object to send.
callbackFunction(optional) Optional callback, returns an error object as the first parameter and the result as the second.

A transaction object of type ACCOUNT_UPDATE has the following structure: Note that when you provide the new key, you should provide just one of the below depending on the key type. If more than one are given, you will receive a 'duplicated key' error. From caver-js v1.2.0, using key with AccountForUpdate instance is recommended.

  • key
  • legacyKey
  • publicKey
  • multisig
  • roleTransactionKey, roleAccountUpdateKey, roleFeePayerKey
  • failKey
NameTypeDescription
typeStringTransaction type. "ACCOUNT_UPDATE"
fromStringAddress of this transaction sender. This account will be updated by this transaction.
gasNumberThe maximum amount of gas willing to pay for the transaction (unused gas is refunded).
gasPriceNumber(optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.
nonceNumber(optional) Integer of a nonce. If omitted, it will be set by caver-js via calling caver.klay.getTransactionCount.
keyObject(optional) An AccountForUpdate instance containing the address and key to be used when updating the account. For instructions on how to create an AccountForUpdate instance for each key type, see caver.klay.accounts.createAccountForUpdate.
legacyKeyBool(optional) if updating the account to have a legacy key, set this true.
publicKeyString(optional) if updating the account to have a public key, write down the 64 bytes public key.
multisigObject(optional) if updating the account to have a multisig key, write down the list of weighted public keys that make up the multisig. multisig also defines the threshold. When signing a transaction, the sum of the weights of the signatures must be larger than or equal to the threshold.
roleTransactionKeyObject(optional) if updating the account to have a role-based key, write down roleTransactionKey. roleTransactionKey can be a public key or a multisig key. This roleTransactionKey will be used when signing a transaction.
roleAccountUpdateKeyObject(optional) if updating the account to have a role-based key, write down roleAccountUpdateKey. roleAccountUpdateKey can be a public key or a multisig key. This roleAccountUpdateKey will be used when signing an AccountUpdate transaction.
roleFeePayerKeyObject(optional) if updating the account to have a role-based key, write down roleFeePayerKey. roleFeePayerKey can be a public key or a multisig key. This roleFeePayerKey will be used when signing a transaction as a feePayer.
failKeyBool(optional) if updating the account to have a fail key, set this true.

If you call caver.klay.sendTransaction with a transaction object of type ACCOUNT_UPDATE as in the above, caver-js will send it to the network after signing with the key of the sender account (from) inside the in-memory wallet.

Return Value

The callback will return the 32-byte transaction hash.

PromiEvent: A promise combined event emitter. Will be resolved when the transaction receipt is available. Additionally the following events are available:

  • "transactionHash" returns String: Is fired right after the transaction is sent and a transaction hash is available.
  • "receipt" returns Object: Is fired when the transaction receipt is available.
  • "error" returns Error: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

Example


const account = caver.klay.accounts.wallet.add('0x{private key}')
// Case 1: Updating account with an AccountForUpdate instance
const accountForUpdate = caver.klay.accounts.createAccountForUpdate(account.address, '0x{private key}')
// using the promise
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
key: accountForUpdate,
gas: '300000',
})
.then(function(receipt){
...
})
// using the event emitter
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
key: accountForUpdate,
gas: '300000',
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error)
// Case 2: Updating account with legacy key
// using the promise
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
legacyKey: true,
gas: '300000',
})
.then(function(receipt){
...
});
// using the event emitter
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
legacyKey: true,
gas: '300000',
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
// Case 3: Updating account with public key
// using the promise
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
publicKey: '0x9016de15ebb219b1e8bc732070df93a28903e5799d0cd24a807a5afabf4601f7e5ab312b5a682dd8c0e72e71e67552174d5082cde25db3626a5b025f97f8a005',
gas: '300000',
})
.then(function(receipt){
...
});
// using the event emitter
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
publicKey: '0x9016de15ebb219b1e8bc732070df93a28903e5799d0cd24a807a5afabf4601f7e5ab312b5a682dd8c0e72e71e67552174d5082cde25db3626a5b025f97f8a005',
gas: '300000',
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
// Case 4: Updating account with fail key
// using the promise
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
failKey: true,
gas: '300000',
})
.then(function(receipt){
...
});
// using the event emitter
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
failKey: true,
gas: '300000',
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
// Case 5: Updating account with weighted-multisig
// using the promise
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
multisig: {
threshold: 3,
keys: [
{ weight: 1, publicKey: '0xb1a73e06009a6ba4816e24018e70fbd6f95b584c61bc704473da5102ac118d3121ce7fc64a7ba5004d487c49865047a7a3d7aa8baec5d9b2c2568f44110daab8' },
{ weight: 1, publicKey: '0x24b437235528893f079b15d65b33a355f315b7a521374f899ae3b3c29c546659dc6bc129cb8de49ccc05617cebf78224a622b9cd238a4fe3b04a5d1f8036efbe' },
{ weight: 1, publicKey: '0x354acd6ef039e69ffc31a690bf6aa748ca76a3dd98c5108793c5e0863a80d3477ebb1fac8c7d3e9a9f6cf57777db28f8ea3efb3937cb17101878b910ee66c527' },
{ weight: 1, publicKey: '0x9016de15ebb219b1e8bc732070df93a28903e5799d0cd24a807a5afabf4601f7e5ab312b5a682dd8c0e72e71e67552174d5082cde25db3626a5b025f97f8a005' },
],
},
gas: '300000',
})
.then(function(receipt){
...
});
// using the event emitter
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
multisig: {
threshold: 3,
keys: [
{ weight: 1, publicKey: '0xb1a73e06009a6ba4816e24018e70fbd6f95b584c61bc704473da5102ac118d3121ce7fc64a7ba5004d487c49865047a7a3d7aa8baec5d9b2c2568f44110daab8' },
{ weight: 1, publicKey: '0x24b437235528893f079b15d65b33a355f315b7a521374f899ae3b3c29c546659dc6bc129cb8de49ccc05617cebf78224a622b9cd238a4fe3b04a5d1f8036efbe' },
{ weight: 1, publicKey: '0x354acd6ef039e69ffc31a690bf6aa748ca76a3dd98c5108793c5e0863a80d3477ebb1fac8c7d3e9a9f6cf57777db28f8ea3efb3937cb17101878b910ee66c527' },
{ weight: 1, publicKey: '0x9016de15ebb219b1e8bc732070df93a28903e5799d0cd24a807a5afabf4601f7e5ab312b5a682dd8c0e72e71e67552174d5082cde25db3626a5b025f97f8a005' },
],
},
gas: '300000',
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
// Case 6: Updating account with role-based key
// using the promise
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
roleTransactionKey: {
publicKey: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d0a5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
},
roleAccountUpdateKey: {
publicKey: '0x36f6355f5b532c3c1606f18fa2be7a16ae200c5159c8031dd25bfa389a4c9c066fdf9fc87a16ac359e66d9761445d5ccbb417fb7757a3f5209d713824596a50d',
},
roleFeePayerKey: {
publicKey: '0xc8785266510368d9372badd4c7f4a94b692e82ba74e0b5e26b34558b0f08144794c27901465af0a703859ab47f8ae17e54aaba453b7cde5a6a9e4a32d45d72b2',
},
gas: '300000',
})
.then(function(receipt){
...
});
// using the event emitter
caver.klay.sendTransaction({
type: 'ACCOUNT_UPDATE',
from: account.address,
roleTransactionKey: {
publicKey: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d0a5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
},
roleAccountUpdateKey: {
publicKey: '0x36f6355f5b532c3c1606f18fa2be7a16ae200c5159c8031dd25bfa389a4c9c066fdf9fc87a16ac359e66d9761445d5ccbb417fb7757a3f5209d713824596a50d',
},
roleFeePayerKey: {
publicKey: '0xc8785266510368d9372badd4c7f4a94b692e82ba74e0b5e26b34558b0f08144794c27901465af0a703859ab47f8ae17e54aaba453b7cde5a6a9e4a32d45d72b2',
},
gas: '300000',
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.

sendTransaction (FEE_DELEGATED_ACCOUNT_UPDATE)


caver.klay.sendTransaction(transactionObject [, callback])

Sends a Fee Delegated Account Update transaction to the network.

There are two ways for a fee payer to sign a transaction and send it to the network.

  1. Call caver.klay.sendTransaction with an object, {senderRawTransaction: rawTransaction, feePayer: feePayerAddress}, a transaction format used for fee payers. In this case, the fee payer account must exist in the in-memory caver-js wallet.
  2. Sign with caver.klay.accounts.feePayerSignTransaction and send to network via caver.klay.sendSignedTransaction

The example here only describes how to use caver.klay.sendTransaction.

For information on how to send using caver.klay.accounts.feePayerSignTransaction and caver.klay.sendSignedTransaction, see caver.klay.accounts.feePayerSignTransaction and Sending a Transaction with multiple signer.

Parameters

The parameters of sendTransaction are a transaction object and a callback function.

NameTypeDescription
transactionObjectObjectThe transaction object to send.
callbackFunction(optional) Optional callback, returns an error object as the first parameter and the result as the second.

A transaction object of type FEE_DELEGATED_ACCOUNT_UPDATE has the following structure:

NameTypeDescription
typeStringTransaction Type. "FEE_DELEGATED_ACCOUNT_UPDATE"
fromStringAddress of this transaction sender. This account will be updated by this transaction.
gasNumberThe maximum amount of gas willing to pay for the transaction (unused gas is refunded).
gasPriceNumber(optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.
nonceNumber(optional) Integer of a nonce. If omitted, it will be set by caver-js via calling caver.klay.getTransactionCount.
keyObject(optional) An AccountForUpdate instance containing the address and key to be used when updating the account. For instructions on how to create an AccountForUpdate instance for each key type, see caver.klay.accounts.createAccountForUpdate.
legacyKeyBool(optional) if updating the account to have a legacy key, set this true.
publicKeyString(optional) if updating the account to have a public key, write down the 64 bytes public key.
multisigObject(optional) if updating the account to have a multisig key, write down the list of weighted public keys that make up the multisig. multisig also defines the threshold. When signing a transaction, the sum of the weights of the signatures must be larger than or equal to the threshold.
roleTransactionKeyObject(optional) if updating the account to have a role-based key, write down roleTransactionKey. roleTransactionKey can be a public key or a multisig key. This roleTransactionKey will be used when signing a transaction.
roleAccountUpdateKeyObject(optional) if updating the account to have a role-based key, write down roleAccountUpdateKey. roleAccountUpdateKey can be a public key or a multisig key. This roleAccountUpdateKey will be used when signing an AccountUpdate transaction.
roleFeePayerKeyObject(optional) if updating the account to have a role-based key, write down roleFeePayerKey. roleFeePayerKey can be a public key or a multisig key. This roleFeePayerKey will be used when signing a transaction as a feePayer.
failKeyBool(optional) if updating the account to have a fail key, set this true.

A transaction object of type FEE_DELEGATED_ACCOUNT_UPDATE with the above structure or an RLP-encoded transaction of type FEE_DELEGATED_ACCOUNT_UPDATE can be used as a parameter in caver.klay.accounts.signTransaction for sender and in caver.klay.accounts.feePayerSignTransaction for fee payer.

In order for the fee payer to sign an RLP encoded transaction signed by the sender and send it to the network, define an object with the following structure and call caver.klay.sendTransaction.

NameTypeDescription
feePayerStringThe fee payer address of the transaction.
senderRawTransactionStringThe RLP-encoded transaction signed by sender.

Return Value

The callback will return the 32-byte transaction hash.

PromiEvent: A promise combined event emitter. Will be resolved when the transaction receipt is available. Additionally the following events are available:

  • "transactionHash" returns String: Is fired right after the transaction is sent and a transaction hash is available.
  • "receipt" returns Object: Is fired when the transaction receipt is available.
  • "error" returns Error: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

Example


const sender = caver.klay.accounts.wallet.add('0x{private key}')
const feePayer = caver.klay.accounts.wallet.add('0x{private key}')
const accountForUpdate = caver.klay.accounts.createAccountForUpdate(sender.address, '0x{private key}')
// using the promise
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
type: 'FEE_DELEGATED_ACCOUNT_UPDATE',
from: sender.address,
key: accountForUpdate,
gas: '300000',
}, sender.privateKey)
caver.klay.sendTransaction({
senderRawTransaction: senderRawTransaction,
feePayer: feePayer.address,
})
.then(function(receipt){
...
})
// using the event emitter
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
type: 'FEE_DELEGATED_ACCOUNT_UPDATE',
from: sender.address,
key: accountForUpdate,
gas: '300000',
}, sender.privateKey)
caver.klay.sendTransaction({
senderRawTransaction: senderRawTransaction,
feePayer: feePayer.address,
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error)

sendTransaction (FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO)


caver.klay.sendTransaction(transactionObject [, callback])

Sends a Fee Delegated Account Update With Ratio transaction to the network.

There are in two ways fee payer sign a transaction and send it to the network.

  1. Call caver.klay.sendTransaction with fee payer transaction format (An object that defines senderRawTransaction and feepayer). In this case, a fee payer account must exist in the in-memory wallet of caver-js.
  2. Sign with caver.klay.accounts.feePayerSignTransaction and send to network via caver.klay.sendSignedTransaction

The example here only describes how to use caver.klay.sendTransaction.

For information on how to send using caver.klay.accounts.feePayerSignTransaction and caver.klay.sendSignedTransaction, see caver.klay.accounts.feePayerSignTransaction and Sending a Transaction with multiple signer.

Parameters

The parameters of sendTransaction are transaction object and callback function.

NameTypeDescription
transactionObjectObjectThe transaction object to send.
callbackFunction(optional) Optional callback, returns an error object as the first parameter and the result as the second.

The plain transaction object type of a FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO transaction has the following structure:

NameTypeDescription
typeStringThe type of "FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO" transaction.
fromStringAddress of this transaction sender. This account will be updated by this transaction.
gasNumberThe maximum amount of gas willing to pay for the transaction (unused gas is refunded).
gasPriceNumber(optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.
nonceNumber(optional) Integer of a nonce. If omitted, it will be set by caver-js via calling caver.klay.getTransactionCount.
keyObject(optional) An AccountForUpdate instance containing the address and key to be used when updating the account. For instructions on how to create an AccountForUpdate instance for each key type, see caver.klay.accounts.createAccountForUpdate.
legacyKeyBool(optional) if updating the account to have a legacy key, set this true.
publicKeyString(optional) if updating the account to have a public key, write down the 64 bytes public key.
multisigObject(optional) if updating the account to have a multisig key, write down the list of weighted public keys that make up the multisig. multisig also defines the threshold. When signing a transaction, the sum of the weights of the signatures must be larger than or equal to the threshold.
roleTransactionKeyObject(optional) if updating the account to have a role-based key, write down roleTransactionKey. roleTransactionKey can be a public key or a multisig key. This roleTransactionKey will be used when signing a transaction.
roleAccountUpdateKeyObject(optional) if updating the account to have a role-based key, write down roleAccountUpdateKey. roleAccountUpdateKey can be a public key or a multisig key. This roleAccountUpdateKey will be used when signing an AccountUpdate transaction.
roleFeePayerKeyObject(optional) if updating the account to have a role-based key, write down roleFeePayerKey. roleFeePayerKey can be a public key or a multisig key. This roleFeePayerKey will be used when signing a transaction as a feePayer.
failKeyBool(optional) if updating the account to have a fail key, set this true.

A transaction object of type FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO with the above structure or an RLP-encoded transaction of type FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO can be used as a parameter in caver.klay.accounts.signTransaction for sender and in caver.klay.accounts.feePayerSignTransaction for fee payer.

In order for the fee payer to sign an RLP encoded transaction signed by the sender and send it to the network, define an object with the following structure and call caver.klay.sendTransaction.

NameTypeDescription
feePayerStringThe fee payer address of the transaction.
senderRawTransactionStringThe RLP-encoded transaction signed by sender.

Return Value

The callback will return the 32-byte transaction hash.

PromiEvent: A promise combined event emitter. Will be resolved when the transaction receipt is available. Additionally the following events are available:

  • "transactionHash" returns String: Is fired right after the transaction is sent and a transaction hash is available.
  • "receipt" returns Object: Is fired when the transaction receipt is available.
  • "error" returns Error: Is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt.

Example


const sender = caver.klay.accounts.wallet.add('0x{private key}')
const feePayer = caver.klay.accounts.wallet.add('0x{private key}')
const accountForUpdate = caver.klay.accounts.createAccountForUpdate(sender.address, '0x{private key}')
// using the promise
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
type: 'FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO',
from: sender.address,
key: accountForUpdate,
gas: '300000',
feeRatio: 30,
}, sender.privateKey)
caver.klay.sendTransaction({
senderRawTransaction: senderRawTransaction,
feePayer: feePayer.address,
})
.then(function(receipt){
...
})
// using the event emitter
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
type: 'FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO',
from: sender.address,
key: accountForUpdate,
gas: '300000',
feeRatio: 30,
}, sender.privateKey)
caver.klay.sendTransaction({
senderRawTransaction: senderRawTransaction,
feePayer: feePayer.address,
})
.on('transactionHash', function(hash){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error)

Make this page better