Contracts
ContractMetadata
¶
__init__(metadata_dict: dict, substrate: SubstrateInterface)
¶
Class using the generated metadata.json file to represent the metadata of a contract. The metadata_dict is parsed and the used types are extracted, composed and added to the type registry of the runtime
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata_dict |
dict
|
required | |
substrate |
SubstrateInterface
|
required |
create_from_file(metadata_file: str, substrate: SubstrateInterface) -> ContractMetadata
classmethod
¶
Create a new ContractMetadata object using the provided metadata_file, usually generated by the command "cargo +nightly contract generate-metadata" in an ink! project
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata_file |
str
|
required | |
substrate |
SubstrateInterface
|
required |
Returns:
Type | Description |
---|---|
ContractMetadata
|
generate_constructor_data(name, args: dict = None) -> ScaleBytes
¶
Compose the data field used in the "Contracts.instantiate" call, finding the selectors and encoded the args of given constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
required | ||
args |
dict
|
None
|
Returns:
Type | Description |
---|---|
ScaleBytes
|
get_type_string_for_metadata_type(type_id: int) -> str
¶
Adds a type included in the metadata (represented by an index in the type list) to the type registry and
produces a type string that can be used in the scope of the RuntimeConfigurationObject
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_id |
int
|
required |
Returns:
Type | Description |
---|---|
str
|
generate_message_data(name, args: dict = None) -> ScaleBytes
¶
Compose the data field used in the "Contracts.call" call, finding the selector and encoded the args of provided message name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
required | ||
args |
dict
|
None
|
Returns:
Type | Description |
---|---|
ScaleBytes
|
get_event_data(event_id: int) -> dict
¶
Looks up the event data for given 0-based event_id
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_id |
int
|
required |
ContractEvent
¶
Bases: ScaleType
__init__(*args, contract_metadata: ContractMetadata = None, **kwargs)
¶
ScaleType class containing information about a specific Contract Event, it decodes the "data" field in the generic "Contracts.ContractExecution" event that is triggered after a successfull "Contracts.call" call.
ContractExecutionReceipt
¶
Bases: ExtrinsicReceipt
__init__(*args, **kwargs)
¶
Object extending the ExtrinsicReceipt
containing more information about the result after submitting a
"Contracts.call" extrinsic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
()
|
||
kwargs |
{}
|
create_from_extrinsic_receipt(receipt: ExtrinsicReceipt, contract_metadata: ContractMetadata) -> ContractExecutionReceipt
classmethod
¶
Promotes a ExtrinsicReceipt object to a ContractExecutionReceipt. It uses the provided ContractMetadata to decode "ContractExecution" events
Parameters:
Name | Type | Description | Default |
---|---|---|---|
receipt |
ExtrinsicReceipt
|
required | |
contract_metadata |
ContractMetadata
|
required |
Returns:
Type | Description |
---|---|
ContractExecutionReceipt
|
ContractCode
¶
__init__(code_hash: bytes = None, metadata: ContractMetadata = None, wasm_bytes: bytes = None, substrate: SubstrateInterface = None)
¶
Object representing the blueprint of the contract, combining either the code hash and metadata of a contract, or the WASM bytes and metadata
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_hash |
bytes
|
None
|
|
metadata |
ContractMetadata
|
None
|
|
wasm_bytes |
bytes
|
None
|
|
substrate |
SubstrateInterface
|
None
|
create_from_contract_files(wasm_file: str, metadata_file: str, substrate: SubstrateInterface) -> ContractCode
classmethod
¶
Create a ContractCode providing paths for the WASM binary file and metadata JSON file generated by the ink! project
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wasm_file |
str
|
required | |
metadata_file |
str
|
required | |
substrate |
SubstrateInterface
|
required |
Returns:
Type | Description |
---|---|
ContractCode
|
create_from_code_hash(code_hash: bytes, metadata_file: str, substrate: SubstrateInterface) -> ContractCode
classmethod
¶
Create a ContractCode providing an existing contract code hash and a path to the metadata JSON file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code_hash |
bytes
|
required | |
metadata_file |
str
|
required | |
substrate |
SubstrateInterface
|
required |
Returns:
Type | Description |
---|---|
ContractCode
|
upload_wasm(keypair: Keypair, storage_deposit_limit: int = None) -> ExtrinsicReceipt
¶
Created and submits an "Contracts.upload_code" extrinsic containing the WASM binary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keypair |
Keypair
|
required | |
storage_deposit_limit |
int
|
None
|
Returns:
Type | Description |
---|---|
ExtrinsicReceipt
|
deploy(keypair: Keypair, constructor: str, args: dict = None, value: int = 0, gas_limit: dict = None, deployment_salt: str = None, upload_code: bool = False, storage_deposit_limit: int = None) -> ContractInstance
¶
Deploys a new instance of the contract after it has been uploaded on-chain, with provided constructor and constructor arguments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keypair |
Keypair
|
required | |
constructor |
str
|
required | |
args |
dict
|
None
|
|
value |
int
|
0
|
|
gas_limit |
dict
|
None
|
|
deployment_salt |
str
|
None
|
|
upload_code |
bool
|
False
|
|
storage_deposit_limit |
int
|
None
|
Returns:
Type | Description |
---|---|
ContractInstance
|
ContractInstance
¶
create_from_address(contract_address: str, metadata_file: str, substrate: SubstrateInterface = None) -> ContractInstance
classmethod
¶
Create a ContractInstance object that already exists on-chain providing a SS58-address and the path to the metadata JSON of that contract
Parameters:
Name | Type | Description | Default |
---|---|---|---|
contract_address |
str
|
required | |
metadata_file |
str
|
required | |
substrate |
SubstrateInterface
|
None
|
Returns:
Type | Description |
---|---|
ContractInstance
|
read(keypair: Keypair, method: str, args: dict = None, value: int = 0, gas_limit: int = None) -> GenericContractExecResult
¶
Used to execute non-mutable messages to for example read data from the contract using getters. Can also be used to predict gas limits and 'dry-run' the execution when a mutable message is used. This method does not submit an extrinsic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keypair |
Keypair
|
required | |
method |
str
|
required | |
args |
dict
|
None
|
|
value |
int
|
0
|
|
gas_limit |
int
|
None
|
Returns:
Type | Description |
---|---|
GenericContractExecResult
|
exec(keypair: Keypair, method: str, args: dict = None, value: int = 0, gas_limit: Optional[dict] = None, storage_deposit_limit: int = None, wait_for_inclusion: bool = True, wait_for_finalization: bool = False) -> ContractExecutionReceipt
¶
Executes provided message by creating and submitting an extrinsic. To get a gas prediction or perform a
'dry-run' of executing this message, see ContractInstance.read
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keypair |
Keypair
|
required | |
method |
str
|
required | |
args |
dict
|
None
|
|
value |
int
|
0
|
|
gas_limit |
Optional[dict]
|
None
|
|
storage_deposit_limit |
int
|
None
|
|
wait_for_inclusion |
bool
|
True
|
|
wait_for_finalization |
bool
|
False
|
Returns:
Type | Description |
---|---|
ContractExecutionReceipt
|