K
K
Klaytn Docs
Search…
caver.contract
The caver.contract object makes it easy to interact with smart contracts on the Klaytn blockchain platform. When you create a new contract object, you have to provide the JSON interface for that smart contract and caver-js will automatically convert all calls with the contract object in javascript into low-level ABI calls over RPC for you.
This allows you to interact with smart contracts as if they were JavaScript objects.

caver.contract.create

1
caver.contract.create(jsonInterface [, address] [, options])
Copied!
Creates a new contract instance with all its methods and events defined in its JSON interface object. This function works the same as new caver.contract.
NOTE caver.contract.create is supported since caver-js v1.6.1.
Parameters
Return Value
Example
1
const contract = caver.contract.create([
2
{
3
constant: true,
4
inputs: [{ name: 'interfaceId', type: 'bytes4' }],
5
name: 'supportsInterface',
6
outputs: [{ name: '', type: 'bool' }],
7
payable: false,
8
stateMutability: 'view',
9
type: 'function',
10
},
11
...
12
], '0x{address in hex}')
Copied!

caver.contract

1
new caver.contract(jsonInterface [, address] [, options])
Copied!
Creates a new contract instance with all its methods and events defined in its JSON interface object.
Parameters
Name
Type
Description
jsonInterface
object
The JSON interface for the contract to instantiate
address
string
(optional) The address of the smart contract to call. Can be added later using myContract.options.address = '0x1234..'
options
object
(optional) The options of the contract. See the table below for the details.
The options object contains the following:
Name
Type
Description
from
string
(optional) The address from which transactions should be made.
gasPrice
string
(optional) The gas price in peb to use for transactions.
gas
number
(optional) The maximum gas provided for a transaction (gas limit).
data
string
(optional) The byte code of the contract. Used when the contract gets deployed.
feeDelegation
boolean
(optional) Whether to use fee delegation transaction.
feePayer
string
(optional) The address of the fee payer paying the transaction fee. When feeDelegation is true, the value is set to the feePayer field in the transaction.
feeRatio
string
(optional) The ratio of the transaction fee the fee payer will be burdened with. If feeDelegation is true and feeRatio is set to a valid value, a partial fee delegation transaction is used. The valid range of this is between 1 and 99. The ratio of 0, or 100 and above are not allowed.
Return Value
Type
Description
object
The contract instance with all its methods and events.
Example
1
const myContract = new caver.contract([...], '0x{address in hex}', { gasPrice: '25000000000' })
Copied!

myContract.options

1
myContract.options
Copied!
The options object for the contract instance. from, gas, gasPrice, feePayer and feeRatio are used as fallback values when sending transactions.
Properties
Name
Type
Description
address
string
The address where the contract is deployed.
jsonInterface
Array
The JSON interface of the contract.
from
string
The default address from which the contract deployment/execution transaction is sent. If the from address is not defined when creating the transaction, this myContract.options.from is always used to create the transaction.
gasPrice
string
The gas price in peb to use for transactions.
gas
number
The maximum gas provided for a transaction (gas limit).
data
string
The byte code of the contract. Used when the contract gets deployed.
feeDelegation
boolean
(optional) Whether to use fee delegation transaction.
feePayer
string
(optional) The address of the fee payer paying the transaction fee. When feeDelegation is true, the value is set to the feePayer field in the transaction.
feeRatio
string
(optional) The ratio of the transaction fee the fee payer will be burdened with. If feeDelegation is true and feeRatio is set to a valid value, a partial fee delegation transaction is used. The valid range of this is between 1 and 99. The ratio of 0, or 100 and above are not allowed.
NOTE feeDelegation, feePayer and feeRatio are supported since caver-js v1.6.1.
Example
1
> myContract.options
2
{
3
address: [Getter/Setter],
4
jsonInterface: [Getter/Setter],
5
from: [Getter/Setter],
6
feePayer: [Getter/Setter],
7
feeDelegation: [Getter/Setter],
8
feeRatio: [Getter/Setter],
9
gasPrice: [Getter/Setter],
10
gas: [Getter/Setter],
11
data: [Getter/Setter]
12
}
13
14
> myContract.options.from = '0x1234567890123456789012345678901234567891' // default from address
15
> myContract.options.gasPrice = '25000000000000' // default gas price in peb
16
> myContract.options.gas = 5000000 // provide as fallback always 5M gas
17
> myContract.options.feeDelegation = true // use fee delegation transaction
18
> myContract.options.feePayer = '0x1234567890123456789012345678901234567891' // default fee payer address
19
> myContract.options.feeRatio = 20 // default fee ratio when send partial fee delegation transaction
Copied!

myContract.options.address

1
myContract.options.address
Copied!
The address used for this contract instance myContract. All transactions generated by caver-js from this contract will contain this address as the to of the transaction.
Property
Name
Type
Description
address
string | null
The address for this contract or null if it is not yet set.
Example
1
> myContract.options.address
2
'0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'
3
4
// set a contract address
5
> myContract.options.address = '0x1234FFDD...'
Copied!

myContract.options.jsonInterface

1
myContract.options.jsonInterface
Copied!
The JSON interface object derived from the ABI of this contract myContract.
Property
Name
Type
Description
jsonInterface
Array
The JSON interface for this contract. Re-setting this will regenerate the methods and events of the contract instance.
Example
1
> myContract.options.jsonInterface
2
[
3
{
4
constant: true,
5
inputs: [ { name: 'interfaceId', type: 'bytes4' } ],
6
name: 'supportsInterface',
7
outputs: [ { name: '', type: 'bool' } ],
8
payable: false,
9
stateMutability: 'view',
10
type: 'function',
11
signature: '0x01ffc9a7',
12
},
13
...
14
{
15
anonymous: false,
16
inputs: [
17
{ indexed: true, name: 'owner', type: 'address' },
18
{ indexed: true, name: 'spender', type: 'address' },
19
{ indexed: false, name: 'value', type: 'uint256' }
20
],
21
name: 'Approval',
22
type: 'event',
23
signature: '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925',
24
},
25
]
26
27
// set a new jsonInterface
28
> myContract.options.jsonInterface = [...]
Copied!

myContract.clone

1
myContract.clone([contractAddress])
Copied!
Clones the current contract instance.
Parameters
Name
Type
Description
contractAddress
String
(optional) The address of the new contract. If omitted, it will be set to the address in the original instance (e.g., myContract.options.address).
Return Value
Type
Description
object
The new cloned contract instance.
Example
1
> myContract.clone()
2
Contract {
3
currentProvider: [Getter/Setter],
4
...
5
_keyrings: KeyringContainer { ... }
6
}
Copied!

myContract.deploy

1
myContract.deploy(options, byteCode [, param1 [, param2 [, ...]]])
Copied!
Deploys the contract to the Klaytn network. After a successful deployment, the promise will be resolved with a new contract instance. Unlike the usability of the existing myContract.deploy function, this function sends a transaction directly to the Klaytn network. You don't need to call send() with the returned object.
NOTE caver.wallet must contains keyring instances corresponding to from and feePayer in options or myContract.options to make signatures.
NOTE myContract.deploy is supported since caver-js v1.6.1.
Parameters
Name
Type
Description
options
object
The options used for sending. See the table in methods.methodName.send for the details.
byteCode
string
The byte code of the contract.
parameters
Mixed
(optional) The parameters that get passed to the constructor on deployment.
Return Value
Promise returning PromiEvent: The promise will be resolved with the new contract instance.
Type
Description
PromiEvent
A promise combined event emitter. It will be resolved when the transaction receipt is available. If send() is called from a myContract.deploy(), then the promise will be resolved with the new contract instance.
For PromiEvent, the following events are available:
  • transactionHash: it is fired right after the transaction is sent and a transaction hash is available. Its type is string.
  • receipt: It is fired when the transaction receipt is available. See caver.rpc.klay.getTransactionReceipt for more details. Its type is object.
  • error: It is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt. Its type is Error.
Example
1
// Deploy a smart contract without constructor arguments
2
> myContract.deploy({
3
from: '0x{address in hex}',
4
gas: 1500000,
5
}, '0x{byte code}')
6
.on('error', function(error) { ... })
7
.on('transactionHash', function(transactionHash) { ... })
8
.on('receipt', function(receipt) {
9
console.log(receipt.contractAddress) // contains the new contract address
10
})
11
.then(function(newContractInstance) {
12
console.log(newContractInstance.options.address) // instance with the new contract address
13
})
14
15
// Deploy a smart contract with constructor arguments
16
> myContract.deploy({
17
from: '0x{address in hex}',
18
gas: 1500000,
19
}, '0x{byte code}', 'keyString', ...)
20
.on('error', function(error) { ... })
21
.on('transactionHash', function(transactionHash) { ... })
22
.on('receipt', function(receipt) {
23
console.log(receipt.contractAddress)
24
})
25
.then(function(newContractInstance) {
26
console.log(newContractInstance.options.address)
27
})
28
29
// Deploy a smart contract with fee delegation transaction (TxTypeFeeDelegatedSmartContractDeploy)
30
> myContract.deploy({
31
from: '0x{address in hex}',
32
feeDelegation: true,
33
feePayer: '0x{address in hex}',
34
gas: 1500000,
35
}, '0x{byte code}')
36
.on('error', function(error) { ... })
37
.on('transactionHash', function(transactionHash) { ... })
38
.on('receipt', function(receipt) {
39
console.log(receipt.contractAddress)
40
})
41
.then(function(newContractInstance) {
42
console.log(newContractInstance.options.address)
43
})
44
45
// Deploy a smart contract with partial fee delegation transaction (TxTypeFeeDelegatedSmartContractDeployWithRatio)
46
> myContract.deploy({
47
from: '0x{address in hex}',
48
feeDelegation: true,
49
feePayer: '0x{address in hex}',
50
feeRatio: 30,
51
gas: 1500000,
52
}, '0x{byte code}')
53
.on('error', function(error) { ... })
54
.on('transactionHash', function(transactionHash) { ... })
55
.on('receipt', function(receipt) {
56
console.log(receipt.contractAddress)
57
})
58
.then(function(newContractInstance) {
59
console.log(newContractInstance.options.address)
60
})
Copied!

myContract.deploy

1
myContract.deploy(options)
Copied!
Returns the object used when deploying the smart contract to the Klaytn. You can send the smart contract deploy transaction via calling myContract.deploy({ data, arguments }).send(options). After a successful deployment, the promise will be resolved with a new contract instance.
Parameters
Name
Type
Description
options
object
The options object used for deployment. See the below table to find the description.
The options object can contain the following:
Name
Type
Description
data
string
The byte code of the contract.
arguments
Array
(optional) The arguments that get passed to the constructor on deployment.
Return Value
Type
Description
object
An object in which arguments and functions for contract distribution are defined. See the below table to find the description.
The object contains the following:
Name
Type
Description
arguments
Array
The arguments passed in options.arguments.
send
function
The function that will deploy the contract to the Klaytn. The promise as the result of this function will be resolved with the new contract instance.
sign
function
The function that will sign a smart contract deploy transaction as a sender. The sign function will return signed transaction.
function
The function that will sign a smart contract deploy transaction as a fee payer. The signAsFeePayer function will return signed transaction.
function
The function that will estimate the gas used for the deployment. The execution of this function does not deploy the contract.
encodeABI
function
The function that encodes the ABI of the deployment, which is contract data + constructor parameters. The execution of this function does not deploy the contract.
NOTE myContract.deploy({ data, arguments }).sign(options) and myContract.deploy({ data, arguments }).signAsFeePayer(options) are supported since caver-js v1.6.1.
Example
1
> myContract.deploy({
2
data: '0x12345...',
3
arguments: [123, 'My string']
4
})
5
.send({
6
from: '0x1234567890123456789012345678901234567891',
7
gas: 1500000,
8
value: 0,
9
}, function(error, transactionHash) { ... })
10
.on('error', function(error) { ... })
11
.on('transactionHash', function(transactionHash) { ... })
12
.on('receipt', function(receipt) {
13
console.log(receipt.contractAddress) // contains the new contract address
14
})
15
.then(function(newContractInstance) {
16
console.log(newContractInstance.options.address) // instance with the new contract address
17
})
18
19
// When the data is already set as an option to the contract itself
20
> myContract.options.data = '0x12345...'
21
22
> myContract.deploy({
23
arguments: [123, 'My string']
24
})
25
.send({
26
from: '0x1234567890123456789012345678901234567891',
27
gas: 1500000,
28
value: 0,
29
})
30
.then(function(newContractInstance) {
31
console.log(newContractInstance.options.address) // instance with the new contract address
32
})
33
34
// Simply encoding
35
> myContract.deploy({
36
data: '0x12345...',
37
arguments: [123, 'My string']
38
})
39
.encodeABI()
40
'0x12345...0000012345678765432'
41
42
// Gas estimation
43
> myContract.deploy({
44
data: '0x12345...',
45
arguments: [123, 'My string']
46
})
47
.estimateGas(function(err, gas) {
48
console.log(gas)
49
})
Copied!

myContract.send

1
myContract.send(options, methodName [, param1 [, param2 [, ...]]])
Copied!
Submits a transaction to execute the function of the smart contract. This can alter the smart contract state.
The transaction type used for this function depends on the options or the value defined in myContract.options. If you want to use a fee-delegated transaction through myContract.send, feeDelegation and feePayer should be set properly.
NOTE caver.wallet must contains keyring instances corresponding to from and feePayer in options or myContract.options to make signatures.
NOTE myContract.send is supported since caver-js v1.6.1.
Parameters
Name
Type
Description
options
object
The options used for sending. See the table in methods.methodName.send for the details.
methodName
string
The method name of the contract function to execute.
parameters
Mixed
(optional) The parameters that get passed to the smart contract function.
Return Value
Promise returns PromiEvent
Type
Description
PromiEvent
A promise combined event emitter. It will be resolved when the transaction receipt is available. The promise will be resolved with the new contract instance.
For PromiEvent, the following events are available:
  • transactionHash: It is fired right after the transaction is sent and a transaction hash is available. Its type is string.
  • receipt: It is fired when the transaction receipt is available. See caver.rpc.klay.getTransactionReceipt for more details. Its type is object.
  • error: It is fired if an error occurs during sending. On an out-of-gas error, the second parameter is the receipt. Its type is Error.
Example
1
// Send a SmartContractExecution and use the promise
2
> myContract.send({ from: '0x{address in hex}', gas: 1000000 }, 'methodName', 123).then(console.log)
3
{
4
blockHash: '0x294202dcd1d3c422880e2a209b9cd70ce7036300536c78ab74130c5717cb90da',
5
blockNumber: 16342,
6
contractAddress: null,
7
from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
8
gas: '0xf4240',
9
gasPrice: '0x5d21dba00',
10
gasUsed: 47411,
11
input: '0x983b2...',
12
logsBloom: '0x00800...',
13
nonce: '0x1cd',
14
senderTxHash: '0xe3f50d2bab2c462ef99379860d2b634d85a0c9fba4e2b189daf1d96bd4bbf8ff',
15
signatures: [ { V: '0x4e43', R: '0x2ba27...', S: '0x50d37...' } ],
16
status: true,
17
to: '0x361870b50834a6afc3358e81a3f7f1b1eb9c7e55',
18
transactionHash: '0xe3f50d2bab2c462ef99379860d2b634d85a0c9fba4e2b189daf1d96bd4bbf8ff',
19
transactionIndex: 0,
20
type: 'TxTypeSmartContractExecution',
21
typeInt: 48,
22
value: '0x0',
23
events: {...}
24
}
25
26
// Send a SmartContractExecution and use the event emitter
27
> myContract.send({ from: '0x{address in hex}', gas: 1000000 }, 'methodName', 123)
28
.on('transactionHash', function(hash) {
29
...
30
})
31
.on('receipt', function(receipt) {
32
console.log(receipt)
33
})
34
.on('error', console.error)
35
36
// Send a FeeDelegatedSmartContractExecution
37
> myContract.send({
38
from: '0x{address in hex}',
39
gas: 1000000,
40
feeDelegation: true,
41
feePayer: '0x{address in hex}',
42
}, 'methodName', 123).then(console.log)
43
{
44
blockHash: '0x149e36f279577c306fccb9779a0274e802501c32f7054c951f592778bd5c168a',
45
blockNumber: 16458,
46
contractAddress: null,
47
feePayer: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
48
feePayerSignatures: [ { V: '0x4e43', R: '0x48c28...', S: '0x18413...' } ],
49
from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
50
gas: '0xf4240',
51
gasPrice: '0x5d21dba00',
52
gasUsed: 57411,
53
input: '0x983b2d5600000000000000000000000022bb89bd35e7b12bd25bea4165cf0f9330032f8c',
54
logsBloom: '0x00800...',
55
nonce: '0x1f5',
56
senderTxHash: '0x5b06ca5046229e066c11dfc0c74fcbc98509294370981f9b142378a8f2bd5fe8',
57
signatures: [ { V: '0x4e44', R: '0xfb707...', S: '0x641c6...' } ],
58
status: true,
59
to: '0x361870b50834a6afc3358e81a3f7f1b1eb9c7e55',
60
transactionHash: '0x0e04be479ad06ec87acbf49abd44f16a56390c736f0a7354860ebc7fc0f92e13',
61
transactionIndex: 1,
62
type: 'TxTypeFeeDelegatedSmartContractExecution',
63
typeInt: 49,
64
value: '0x0',
65
events: {...}
66
}
67
68
// Send a FeeDelegatedSmartContractExecutionWithRatio
69
> myContract.send({
70
from: '0x{address in hex}',
71
gas: 1000000,
72
feeDelegation: true,
73
feePayer: '0x{address in hex}',
74
feeRatio: 30,
75
}, 'methodName', 123).then(console.log)
76
{
77
blockHash: '0x8f0a0137cf7e0fea503c818910140246437db36121871bc54b2ebc688873b3f3',
78
blockNumber: 16539,
79
contractAddress: null,
80
feePayer: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
81
feePayerSignatures: [ { V: '0x4e43', R: '0x80db0...', S: '0xf8c7c...' } ],
82
feeRatio: '0x1e',
83
from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
84
gas: '0xf4240',
85
gasPrice: '0x5d21dba00',
86
gasUsed: 62411,
87
input: '0x983b2d560000000000000000000000007ad1a538041fa3ba1a721f87203cb1a3822b8eaa',
88
logsBloom: '0x00800...',
89
nonce: '0x219',
90
senderTxHash: '0x14c7b674a0e253b31c85c7be8cbfe4bf9d86e66e940fcae34b854e25eab1ce15',
91
signatures: [ { V: '0x4e43', R: '0xd57ef...', S: '0xe14f3...' } ],
92
status: true,
93
to: '0x361870b50834a6afc3358e81a3f7f1b1eb9c7e55',
94
transactionHash: '0xfbf00ec189aeb0941d554384f1660ffdac7768b3af2bb1526bcb3983215c1183',
95
transactionIndex: 0,
96
type: 'TxTypeFeeDelegatedSmartContractExecutionWithRatio',
97
typeInt: 50,
98
value: '0x0',
99
events: {...}
100
}
Copied!

myContract.sign

1
myContract.sign(options, methodName [, param1 [, param2 [, ...]]])
Copied!
Signs a smart contract transaction as a sender to deploy the smart contract or execute the function of the smart contract.
If a smart contract is deployed, 'constructor' can be entered in the methodName, such as myContract.sign({ from, ... }, 'constructor', byteCode, ...).
The transaction type used for this function depends on the options or the value defined in myContract.options. If you want to use a fee-delegated transaction through myContract.sign, feeDelegation should be defined as true.
NOTE caver.wallet must contains keyring instances corresponding to from in options or myContract.options to make signatures.
NOTE myContract.sign is supported since caver-js v1.6.1.
Parameters
Name
Type
Description
options
object
The options used for sending. See the table in methods.methodName.send for the details.
methodName
string
The method name of the contract function to execute. If you want to sign a transaction for deploying the smart contract, use 'constructor' string instead of method name.
parameters
Mixed
(optional) The parameters that get passed to the smart contract function. If you want to sign a smart contract deploy transaction, pass the byteCode and constructor parameters.
Return Value
Promise returning Transaction - The signed smart contract transaction.
Example
1
// Sign a SmartContractDeploy
2
> myContract.sign({ from: '0x{address in hex}', gas: 1000000 }, 'constructor', byteCode, 123).then(console.log)
3
SmartContractDeploy {
4
_type: 'TxTypeSmartContractDeploy',
5
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
6
_gas: '0xf4240',
7
_signatures: [ SignatureData { _v: '0x4e43', _r: '0xeb6b5...', _s: '0x5e4f9...' } ],
8
_to: '0x',
9
_value: '0x0',
10
_input: '0x60806...',
11
_humanReadable: false,
12
_codeFormat: '0x0',
13
_chainId: '0x2710',
14
_gasPrice: '0x5d21dba00',
15
_nonce: '0x2a5'
16
}
17
18
// Sign a FeeDelegatedSmartContractDeploy
19
> myContract.sign({ from: '0x{address in hex}', feeDelegation: true, gas: 1000000 }, 'constructor', byteCode, 123).then(console.log)
20
FeeDelegatedSmartContractDeploy {
21
_type: 'TxTypeFeeDelegatedSmartContractDeploy',
22
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
23
_gas: '0xf4240',
24
_signatures: [ SignatureData { _v: '0x4e43', _r: '0xee0f5...', _s: '0x31cbf...' } ],
25
_feePayer: '0x0000000000000000000000000000000000000000',
26
_feePayerSignatures: [ SignatureData { _v: '0x01', _r: '0x', _s: '0x' } ],
27
_to: '0x',
28
_value: '0x0',
29
_input: '0x60806...',
30
_humanReadable: false,
31
_codeFormat: '0x0',
32
_chainId: '0x2710',
33
_gasPrice: '0x5d21dba00',
34
_nonce: '0x320'
35
}
36
37
// Sign a FeeDelegatedSmartContractDeployWithRatio
38
> myContract.sign({ from: keyring.address, feeDelegation: true, feeRatio: 30, gas: 1000000 }, 'constructor', byteCode, 123).then(console.log)
39
FeeDelegatedSmartContractDeployWithRatio {
40
_type: 'TxTypeFeeDelegatedSmartContractDeployWithRatio',
41
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
42
_gas: '0xf4240',
43
_signatures: [ SignatureData { _v: '0x4e44', _r: '0x4c2b0...', _s: '0x47df8...' } ],
44
_feePayer: '0x0000000000000000000000000000000000000000',
45
_feePayerSignatures: [ SignatureData { _v: '0x01', _r: '0x', _s: '0x' } ],
46
_feeRatio: '0x1e',
47
_to: '0x',
48
_value: '0x0',
49
_input: '0x60806...',
50
_humanReadable: false,
51
_codeFormat: '0x0',
52
_chainId: '0x2710',
53
_gasPrice: '0x5d21dba00',
54
_nonce: '0x306'
55
}
56
57
// Sign a SmartContractExecution
58
> myContract.sign({ from: '0x{address in hex}', gas: 1000000 }, 'methodName', 123).then(console.log)
59
SmartContractExecution {
60
_type: 'TxTypeSmartContractExecution',
61
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
62
_gas: '0xf4240',
63
_signatures: [ SignatureData { _v: '0x4e44', _r: '0xb2846...', _s: '0x422c1...' } ],
64
_to: '0x361870b50834a6afc3358e81a3f7f1b1eb9c7e55',
65
_value: '0x0',
66
_input: '0x983b2...',
67
_chainId: '0x2710',
68
_gasPrice: '0x5d21dba00',
69
_nonce: '0x23b'
70
}
71
72
// Sign a FeeDelegatedSmartContractExecution
73
> myContract.sign({
74
from: '0x{address in hex}',
75
gas: 1000000,
76
feeDelegation: true,
77
}, 'methodName', 123).then(console.log)
78
FeeDelegatedSmartContractExecution {
79
_type: 'TxTypeFeeDelegatedSmartContractExecution',
80
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
81
_gas: '0xf4240',
82
_signatures: [ SignatureData { _v: '0x4e43', _r: '0xf7676...', _s: '0x42673...' } ],
83
_feePayer: '0x0000000000000000000000000000000000000000',
84
_feePayerSignatures: [ SignatureData { _v: '0x01', _r: '0x', _s: '0x' } ],
85
_to: '0x361870b50834a6afc3358e81a3f7f1b1eb9c7e55',
86
_value: '0x0',
87
_input: '0x983b2...',
88
_chainId: '0x2710',
89
_gasPrice: '0x5d21dba00',
90
_nonce: '0x254'
91
}
92
93
// Sign a FeeDelegatedSmartContractExecutionWithRatio
94
> myContract.sign({
95
from: '0x{address in hex}',
96
gas: 1000000,
97
feeDelegation: true,
98
feeRatio: 30,
99
}, 'methodName', 123).then(console.log)
100
FeeDelegatedSmartContractExecutionWithRatio {
101
_type: 'TxTypeFeeDelegatedSmartContractExecutionWithRatio',
102
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
103
_gas: '0xf4240',
104
_signatures: [ SignatureData { _v: '0x4e44', _r: '0x58b06...', _s: '0x637ff...' } ],
105
_feePayer: '0x0000000000000000000000000000000000000000',
106
_feePayerSignatures: [ SignatureData { _v: '0x01', _r: '0x', _s: '0x' } ],
107
_feeRatio: '0x1e',
108
_to: '0x361870b50834a6afc3358e81a3f7f1b1eb9c7e55',
109
_value: '0x0',
110
_input: '0x983b2...',
111
_chainId: '0x2710',
112
_gasPrice: '0x5d21dba00',
113
_nonce: '0x262'
114
}
Copied!

myContract.signAsFeePayer

1
myContract.signAsFeePayer(options, methodName [, param1 [, param2 [, ...]]])
Copied!
Signs a smart contract transaction as a fee payer to deploy the smart contract or execute the function of the smart contract.
If a smart contract is deployed, 'constructor' can be entered in the methodName, such as myContract.signAsFeePayer({ from, feeDelegation: true, feePayer, ... }, 'constructor', byteCode, ...).
The transaction type used for this function depends on the options or the value defined in myContract.options. The signAsFeePayer is a function that signs as a transaction fee payer, so feeDelegation field must be defined as true. Also, the address of the fee payer must be defined in the feePayer field.
NOTE caver.wallet must contains keyring instances corresponding to feePayer in options or myContract.options to make signatures.
NOTE myContract.signAsFeePayer is supported since caver-js v1.6.1.
Parameters
Name
Type
Description
options
object
The options used for sending. See the table in methods.methodName.send for the details.
methodName
string
The method name of the contract function to execute. If you want to sign a transaction for deploying the smart contract, use 'constructor' string instead of method name.
parameters
Mixed
(optional) The parameters that get passed to the smart contract function. If you want to sign a smart contract deploy transaction, pass the byteCode and constructor parameters.
Return Value
Promise returning Transaction - The signed smart contract transaction.
Example
1
// Sign a FeeDelegatedSmartContractDeploy
2
> myContract.signAsFeePayer({ from: '0x{address in hex}', feeDelegation: true, feePayer: '0x{address in hex}', gas: 1000000 }, 'constructor', byteCode, 123).then(console.log)
3
FeeDelegatedSmartContractDeploy {
4
_type: 'TxTypeFeeDelegatedSmartContractDeploy',
5
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
6
_gas: '0xf4240',
7
_signatures: [ SignatureData { _v: '0x01', _r: '0x', _s: '0x' } ],
8
_feePayer: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
9
_feePayerSignatures: [ SignatureData { _v: '0x4e43', _r: '0xe0641...', _s: '0x1d21e...' } ],
10
_to: '0x',
11
_value: '0x0',
12
_input: '0x60806...',
13
_humanReadable: false,
14
_codeFormat: '0x0',
15
_chainId: '0x2710',
16
_gasPrice: '0x5d21dba00',
17
_nonce: '0x32a'
18
}
19
20
// Sign a FeeDelegatedSmartContractDeployWithRatio
21
> myContract.signAsFeePayer({ from: keyring.address, feeDelegation: true, feePayer: '0x{address in hex}', feeRatio: 30, gas: 1000000 }, 'constructor', byteCode, 123).then(console.log)
22
FeeDelegatedSmartContractDeployWithRatio {
23
_type: 'TxTypeFeeDelegatedSmartContractDeployWithRatio',
24
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
25
_gas: '0xf4240',
26
_signatures: [ SignatureData { _v: '0x01', _r: '0x', _s: '0x' } ],
27
_feePayer: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
28
_feePayerSignatures: [ SignatureData { _v: '0x4e44', _r: '0x307bd...', _s: '0x75110...' } ],
29
_feeRatio: '0x1e',
30
_to: '0x',
31
_value: '0x0',
32
_input: '0x60806...',
33
_humanReadable: false,
34
_codeFormat: '0x0',
35
_chainId: '0x2710',
36
_gasPrice: '0x5d21dba00',
37
_nonce: '0x359'
38
}
39
40
// Sign a FeeDelegatedSmartContractExecution
41
> myContract.signAsFeePayer({
42
from: '0x{address in hex}',
43
gas: 1000000,
44
feeDelegation: true,
45
feePayer: '0x{address in hex}',
46
}, 'methodName', 123).then(console.log)
47
FeeDelegatedSmartContractExecution {
48
_type: 'TxTypeFeeDelegatedSmartContractExecution',
49
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
50
_gas: '0xf4240',
51
_signatures: [ SignatureData { _v: '0x01', _r: '0x', _s: '0x' } ],
52
_feePayer: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
53
_feePayerSignatures: [ SignatureData { _v: '0x4e43', _r: '0xc58ba...', _s: '0x76fdb...' } ],
54
_to: '0x4a9d979707aede18fa674711f3b2fe110fac4e7e',
55
_value: '0x0',
56
_input: '0x983b2...',
57
_chainId: '0x2710',
58
_gasPrice: '0x5d21dba00',
59
_nonce: '0x36c'
60
}
61
62
// Sign a FeeDelegatedSmartContractExecutionWithRatio
63
> myContract.signAsFeePayer({
64
from: '0x{address in hex}',
65
gas: 1000000,
66
feeDelegation: true,
67
feePayer: '0x{address in hex}',
68
feeRatio: 30,
69
}, 'methodName', 123).then(console.log)
70
FeeDelegatedSmartContractExecutionWithRatio {
71
_type: 'TxTypeFeeDelegatedSmartContractExecutionWithRatio',
72
_from: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
73
_gas: '0xf4240',
74
_signatures: [ SignatureData { _v: '0x01', _r: '0x', _s: '0x' } ],
75
_feePayer: '0x69c3a6e3485446118d8081063dcef2e65b69ae91',
76
_feePayerSignatures: [ SignatureData { _v: '0x4e44', _r: '0xeb78d...', _s: '0x2864d...' } ],
77
_feeRatio: '0x1e',
78
_to: '0x4a9d979707aede18fa674711f3b2fe110fac4e7e',
79
_value: '0x0',
80
_input: '0x983b2...',
81
_chainId: '0x2710',
82
_gasPrice: '0x5d21dba00',
83
_nonce: '0x37b'
84
}
Copied!

myContract.call

1
myContract.call('methodName', [param1 [, param2 [, ...]]])
2
myContract.call(options, 'methodName', [param1 [, param2 [, ...]]])
Copied!
Will call a constant method and execute its smart contract method in the Klaytn Virtual Machine without sending any transaction. Note that calling cannot alter the smart contract state.
NOTE myContract.call is supported since caver-js v1.6.1.
Parameters
Name
Type
Description
options
object
(optional) The options used for calling. See the table in methods.methodName.call for the details.
methodName
string
The method name of the contract function to call.
parameters
Mixed
(optional) The parameters that get passed to the smart contract function.
Return Value
Promise returning Mixed - The return value(s) of the smart contract method. If it returns a single value, it is returned as it is. If it has multiple return values, it returns an object with properties and indices.
Example
1
> myContract.call('methodName').then(console.log)
2
Jasmine
3
4
> myContract.call({ from: '0x{address in hex}' }, 'methodName', 123).then(console.log)
5
Test Result
Copied!

myContract.decodeFunctionCall

1
myContract.decodeFunctionCall(functionCall)
Copied!
Decodes a function call and returns parameters.
NOTE myContract.decodeFunctionCall is supported since caver-js