Klaytn Docs
Search…
Account Update

sendTransaction (ACCOUNT_UPDATE)

1
caver.klay.sendTransaction(transactionObject [, callback])
Copied!
Sends an Account Update transaction to the network.
Parameters
The parameters of sendTransaction are a transaction object and a callback function.
Name
Type
Description
transactionObject
Object
The transaction object to send.
callback
Function
(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
Name
Type
Description
type
String
Transaction type. "ACCOUNT_UPDATE"
from
String
Address of this transaction sender. This account will be updated by this transaction.
gas
Number
The maximum amount of gas willing to pay for the transaction (unused gas is refunded).
gasPrice
Number
(optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.
nonce
Number
(optional) Integer of a nonce. If omitted, it will be set by caver-js via calling caver.klay.getTransactionCount.
key
Object
(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.
legacyKey
Bool
(optional) if updating the account to have a legacy key, set this true.
publicKey
String
(optional) if updating the account to have a public key, write down the 64 bytes public key.
multisig
Object
(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.
roleTransactionKey
Object
(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.
roleAccountUpdateKey
Object
(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.
roleFeePayerKey
Object
(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.
failKey
Bool
(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
1
const account = caver.klay.accounts.wallet.add('0x{private key}')
2
3
// Case 1: Updating account with an AccountForUpdate instance
4
5
const accountForUpdate = caver.klay.accounts.createAccountForUpdate(account.address, '0x{private key}')
6
7
// using the promise
8
caver.klay.sendTransaction({
9
type: 'ACCOUNT_UPDATE',
10
from: account.address,
11
key: accountForUpdate,
12
gas: '300000',
13
})
14
.then(function(receipt){
15
...
16
})
17
18
// using the event emitter
19
caver.klay.sendTransaction({
20
type: 'ACCOUNT_UPDATE',
21
from: account.address,
22
key: accountForUpdate,
23
gas: '300000',
24
})
25
.on('transactionHash', function(hash){
26
...
27
})
28
.on('receipt', function(receipt){
29
...
30
})
31
.on('error', console.error)
32
33
// Case 2: Updating account with legacy key
34
35
// using the promise
36
caver.klay.sendTransaction({
37
type: 'ACCOUNT_UPDATE',
38
from: account.address,
39
legacyKey: true,
40
gas: '300000',
41
})
42
.then(function(receipt){
43
...
44
});
45
46
// using the event emitter
47
caver.klay.sendTransaction({
48
type: 'ACCOUNT_UPDATE',
49
from: account.address,
50
legacyKey: true,
51
gas: '300000',
52
})
53
.on('transactionHash', function(hash){
54
...
55
})
56
.on('receipt', function(receipt){
57
...
58
})
59
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
60
61
// Case 3: Updating account with public key
62
63
// using the promise
64
caver.klay.sendTransaction({
65
type: 'ACCOUNT_UPDATE',
66
from: account.address,
67
publicKey: '0x9016de15ebb219b1e8bc732070df93a28903e5799d0cd24a807a5afabf4601f7e5ab312b5a682dd8c0e72e71e67552174d5082cde25db3626a5b025f97f8a005',
68
gas: '300000',
69
})
70
.then(function(receipt){
71
...
72
});
73
74
// using the event emitter
75
caver.klay.sendTransaction({
76
type: 'ACCOUNT_UPDATE',
77
from: account.address,
78
publicKey: '0x9016de15ebb219b1e8bc732070df93a28903e5799d0cd24a807a5afabf4601f7e5ab312b5a682dd8c0e72e71e67552174d5082cde25db3626a5b025f97f8a005',
79
gas: '300000',
80
})
81
.on('transactionHash', function(hash){
82
...
83
})
84
.on('receipt', function(receipt){
85
...
86
})
87
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
88
89
// Case 4: Updating account with fail key
90
91
// using the promise
92
caver.klay.sendTransaction({
93
type: 'ACCOUNT_UPDATE',
94
from: account.address,
95
failKey: true,
96
gas: '300000',
97
})
98
.then(function(receipt){
99
...
100
});
101
102
// using the event emitter
103
caver.klay.sendTransaction({
104
type: 'ACCOUNT_UPDATE',
105
from: account.address,
106
failKey: true,
107
gas: '300000',
108
})
109
.on('transactionHash', function(hash){
110
...
111
})
112
.on('receipt', function(receipt){
113
...
114
})
115
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
116
117
// Case 5: Updating account with weighted-multisig
118
119
// using the promise
120
caver.klay.sendTransaction({
121
type: 'ACCOUNT_UPDATE',
122
from: account.address,
123
multisig: {
124
threshold: 3,
125
keys: [
126
{ weight: 1, publicKey: '0xb1a73e06009a6ba4816e24018e70fbd6f95b584c61bc704473da5102ac118d3121ce7fc64a7ba5004d487c49865047a7a3d7aa8baec5d9b2c2568f44110daab8' },
127
{ weight: 1, publicKey: '0x24b437235528893f079b15d65b33a355f315b7a521374f899ae3b3c29c546659dc6bc129cb8de49ccc05617cebf78224a622b9cd238a4fe3b04a5d1f8036efbe' },
128
{ weight: 1, publicKey: '0x354acd6ef039e69ffc31a690bf6aa748ca76a3dd98c5108793c5e0863a80d3477ebb1fac8c7d3e9a9f6cf57777db28f8ea3efb3937cb17101878b910ee66c527' },
129
{ weight: 1, publicKey: '0x9016de15ebb219b1e8bc732070df93a28903e5799d0cd24a807a5afabf4601f7e5ab312b5a682dd8c0e72e71e67552174d5082cde25db3626a5b025f97f8a005' },
130
],
131
},
132
gas: '300000',
133
})
134
.then(function(receipt){
135
...
136
});
137
138
// using the event emitter
139
caver.klay.sendTransaction({
140
type: 'ACCOUNT_UPDATE',
141
from: account.address,
142
multisig: {
143
threshold: 3,
144
keys: [
145
{ weight: 1, publicKey: '0xb1a73e06009a6ba4816e24018e70fbd6f95b584c61bc704473da5102ac118d3121ce7fc64a7ba5004d487c49865047a7a3d7aa8baec5d9b2c2568f44110daab8' },
146
{ weight: 1, publicKey: '0x24b437235528893f079b15d65b33a355f315b7a521374f899ae3b3c29c546659dc6bc129cb8de49ccc05617cebf78224a622b9cd238a4fe3b04a5d1f8036efbe' },
147
{ weight: 1, publicKey: '0x354acd6ef039e69ffc31a690bf6aa748ca76a3dd98c5108793c5e0863a80d3477ebb1fac8c7d3e9a9f6cf57777db28f8ea3efb3937cb17101878b910ee66c527' },
148
{ weight: 1, publicKey: '0x9016de15ebb219b1e8bc732070df93a28903e5799d0cd24a807a5afabf4601f7e5ab312b5a682dd8c0e72e71e67552174d5082cde25db3626a5b025f97f8a005' },
149
],
150
},
151
gas: '300000',
152
})
153
.on('transactionHash', function(hash){
154
...
155
})
156
.on('receipt', function(receipt){
157
...
158
})
159
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
160
161
// Case 6: Updating account with role-based key
162
163
// using the promise
164
caver.klay.sendTransaction({
165
type: 'ACCOUNT_UPDATE',
166
from: account.address,
167
roleTransactionKey: {
168
publicKey: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d0a5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
169
},
170
roleAccountUpdateKey: {
171
publicKey: '0x36f6355f5b532c3c1606f18fa2be7a16ae200c5159c8031dd25bfa389a4c9c066fdf9fc87a16ac359e66d9761445d5ccbb417fb7757a3f5209d713824596a50d',
172
},
173
roleFeePayerKey: {
174
publicKey: '0xc8785266510368d9372badd4c7f4a94b692e82ba74e0b5e26b34558b0f08144794c27901465af0a703859ab47f8ae17e54aaba453b7cde5a6a9e4a32d45d72b2',
175
},
176
gas: '300000',
177
})
178
.then(function(receipt){
179
...
180
});
181
182
// using the event emitter
183
caver.klay.sendTransaction({
184
type: 'ACCOUNT_UPDATE',
185
from: account.address,
186
roleTransactionKey: {
187
publicKey: '0xe4a01407460c1c03ac0c82fd84f303a699b210c0b054f4aff72ff7dcdf01512d0a5735a23ce1654b14680054a993441eae7c261983a56f8e0da61280758b5919',
188
},
189
roleAccountUpdateKey: {
190
publicKey: '0x36f6355f5b532c3c1606f18fa2be7a16ae200c5159c8031dd25bfa389a4c9c066fdf9fc87a16ac359e66d9761445d5ccbb417fb7757a3f5209d713824596a50d',
191
},
192
roleFeePayerKey: {
193
publicKey: '0xc8785266510368d9372badd4c7f4a94b692e82ba74e0b5e26b34558b0f08144794c27901465af0a703859ab47f8ae17e54aaba453b7cde5a6a9e4a32d45d72b2',
194
},
195
gas: '300000',
196
})
197
.on('transactionHash', function(hash){
198
...
199
})
200
.on('receipt', function(receipt){
201
...
202
})
203
.on('error', console.error); // If an out-of-gas error, the second parameter is the receipt.
Copied!

sendTransaction (FEE_DELEGATED_ACCOUNT_UPDATE)

1
caver.klay.sendTransaction(transactionObject [, callback])
Copied!
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. 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.
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.
Name
Type
Description
transactionObject
Object
The transaction object to send.
callback
Function
(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:
Name
Type
Description
type
String
Transaction Type. "FEE_DELEGATED_ACCOUNT_UPDATE"
from
String
Address of this transaction sender. This account will be updated by this transaction.
gas
Number
The maximum amount of gas willing to pay for the transaction (unused gas is refunded).
gasPrice
Number
(optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.
nonce
Number
(optional) Integer of a nonce. If omitted, it will be set by caver-js via calling caver.klay.getTransactionCount.
key
Object
(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.
legacyKey
Bool
(optional) if updating the account to have a legacy key, set this true.
publicKey
String
(optional) if updating the account to have a public key, write down the 64 bytes public key.
multisig
Object
(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.
roleTransactionKey
Object
(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.
roleAccountUpdateKey
Object
(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.
roleFeePayerKey
Object
(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.
failKey
Bool
(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.
Name
Type
Description
feePayer
String
The fee payer address of the transaction.
senderRawTransaction
String
The 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
1
const sender = caver.klay.accounts.wallet.add('0x{private key}')
2
const feePayer = caver.klay.accounts.wallet.add('0x{private key}')
3
4
const accountForUpdate = caver.klay.accounts.createAccountForUpdate(sender.address, '0x{private key}')
5
6
// using the promise
7
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
8
type: 'FEE_DELEGATED_ACCOUNT_UPDATE',
9
from: sender.address,
10
key: accountForUpdate,
11
gas: '300000',
12
}, sender.privateKey)
13
14
caver.klay.sendTransaction({
15
senderRawTransaction: senderRawTransaction,
16
feePayer: feePayer.address,
17
})
18
.then(function(receipt){
19
...
20
})
21
22
// using the event emitter
23
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
24
type: 'FEE_DELEGATED_ACCOUNT_UPDATE',
25
from: sender.address,
26
key: accountForUpdate,
27
gas: '300000',
28
}, sender.privateKey)
29
30
caver.klay.sendTransaction({
31
senderRawTransaction: senderRawTransaction,
32
feePayer: feePayer.address,
33
})
34
.on('transactionHash', function(hash){
35
...
36
})
37
.on('receipt', function(receipt){
38
...
39
})
40
.on('error', console.error)
Copied!

sendTransaction (FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO)

1
caver.klay.sendTransaction(transactionObject [, callback])
Copied!
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. 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.
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.
Name
Type
Description
transactionObject
Object
The transaction object to send.
callback
Function
(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:
Name
Type
Description
type
String
The type of "FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO" transaction.
from
String
Address of this transaction sender. This account will be updated by this transaction.
gas
Number
The maximum amount of gas willing to pay for the transaction (unused gas is refunded).
gasPrice
Number
(optional) Gas price provided by the sender in peb. The gasPrice must be the same as the unitPrice set in the Klaytn node.
nonce
Number
(optional) Integer of a nonce. If omitted, it will be set by caver-js via calling caver.klay.getTransactionCount.
key
Object
(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.
legacyKey
Bool
(optional) if updating the account to have a legacy key, set this true.
publicKey
String
(optional) if updating the account to have a public key, write down the 64 bytes public key.
multisig
Object
(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.
roleTransactionKey
Object
(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.
roleAccountUpdateKey
Object
(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.
roleFeePayerKey
Object
(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.
failKey
Bool
(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.
Name
Type
Description
feePayer
String
The fee payer address of the transaction.
senderRawTransaction
String
The 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
1
const sender = caver.klay.accounts.wallet.add('0x{private key}')
2
const feePayer = caver.klay.accounts.wallet.add('0x{private key}')
3
4
const accountForUpdate = caver.klay.accounts.createAccountForUpdate(sender.address, '0x{private key}')
5
6
// using the promise
7
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
8
type: 'FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO',
9
from: sender.address,
10
key: accountForUpdate,
11
gas: '300000',
12
feeRatio: 30,
13
}, sender.privateKey)
14
15
caver.klay.sendTransaction({
16
senderRawTransaction: senderRawTransaction,
17
feePayer: feePayer.address,
18
})
19
.then(function(receipt){
20
...
21
})
22
23
// using the event emitter
24
const { rawTransaction: senderRawTransaction } = await caver.klay.accounts.signTransaction({
25
type: 'FEE_DELEGATED_ACCOUNT_UPDATE_WITH_RATIO',
26
from: sender.address,
27
key: accountForUpdate,
28
gas: '300000',
29
feeRatio: 30,
30
}, sender.privateKey)
31
32
caver.klay.sendTransaction({
33
senderRawTransaction: senderRawTransaction,
34
feePayer: feePayer.address,
35
})
36
.on('transactionHash', function(hash){
37
...
38
})
39
.on('receipt', function(receipt){
40
...
41
})
42
.on('error', console.error)
Copied!