Last updated
Last updated
The caver.klay.Contract
object makes it easy to interact with smart contracts on the Klaytn blockchain. When you create a new contract object, you give it the JSON interface of the respective smart contract and caver will auto convert all calls into low level ABI calls over RPC for you.
This allows you to interact with smart contracts as if they were JavaScript objects.
Creates a new contract instance with all its methods and events defined in its JSON interface object.
Parameters
The options object contains the following:
Return Value
Example
The options
object for the contract instance. from
, gas
and gasPrice
are used as fallback values when sending transactions.
Properties
Example
The address used for this contract instance myContract
. All transactions generated by caver-js from this contract will contain this address as the "to". 주소는 소문자로 저장됩니다.
Property
Example
The JSON interface object derived from the ABI of this contract myContract
.
Property
Example
Clones the current contract instance.
Parameters
None
Return Value
Example
컨트랙트를 Klaytn 블록체인에 배포합니다. After successful deployment, the promise will be resolved with a new contract instance.
Parameters
options
: 배포에 사용되는 옵션 객체:
Return Value
Object
: 트랜잭션 객체:
Example
Creates a transaction object for that method, which then can be called, sent, estimated or ABI encoded.
이 스마트 컨트랙트의 메소드는 다음을 통해 이용할 수 있습니다:
이름: myContract.methods.myMethod(123)
매개변수가 있는 이름: myContract.methods['myMethod(uint256)'](123)
The signature*: myContract.methods['0x58cf5f10'](123)
This allows calling functions with the same name but different parameters from the JavaScript contract object.
The first four bytes of the call data for a function call specifies the function to be called. It is the first (left, high-order in big-endian) four bytes of the Keccak-256 (SHA-3) hash of the signature of the function.
The function signature can be made by 2 different methods.
1. caver.klay.abi.encodeFunctionSignature('funcName(paramType1,paramType2,...)')
2. caver.utils.sha3('funcName(paramType1,paramType2,...)').substr(0, 10)
ex)
Parameters
모든 메소드의 매개변수는 JSON 인터페이스에 정의된 스마트 컨트랙트 메소드에 의존합니다.
Return Value
Object
: The transaction object:
Example
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.
Parameters
The options object can contain the following:
Return Value
Promise
returns 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, they are returned as an object with properties and indices.
Example
스마트 컨트랙트에 트랜잭션을 보내고 그 메소드를 실행합니다. Note that this can alter the smart contract state.
Parameters
The options object can contain the following:
Return Value
callback
은 32바이트 트랜잭션 해시를 반환합니다.
PromiEvent
: 프로미스(promise)가 조합된 이벤트 이미터(event emitter). Will be resolved when the transaction receipt is available, or if this send()
is called from a someContract.deploy()
, then the promise will be resolved with the new contract instance. 추가로 다음과 같은 이벤트를 사용할 수 있습니다:
Example
Will estimate the gas that a method execution will take when executed in the Klaytn Virtual Machine. The estimation can differ from the actual gas used when later sending a transaction, as the state of the smart contract can be different at that time.
Parameters
The options object can contain the following:
Return Value
Promise
는 Number
를 반환합니다 - 모의 호출/트랜잭션에 사용된 가스.
Example
Encodes the ABI for this method. This can be used to send a transaction, call a method, or pass it into another smart contract method as arguments.
Parameters
None
Return Value
Example
Subscribes to an event and unsubscribes immediately after the first event or error. Will only fire for a single event.
Parameters
The options object can contain the following:
Return Value
undefined
Example
이벤트를 구독합니다.
Parameters
The options object can contain the following:
Return Value
EventEmitter
: 이벤트 이미터는 다음 이벤트를 가집니다:
반환된 이벤트 Object
의 구조는 다음과 같습니다:
Example
이 컨트랙트의 이전 이벤트를 가져옵니다.
Parameters
옵션 개체에는 다음이 포함됩니다:
Return Value
Promise
returns Array
: An array with the past event objects, matching the given event name and filter.
Example
Same as but receives all events from this smart contract. 선택적으로 filter 속성은 해당 이벤트를 필터링할 수 있습니다.