|
5 | 5 | A smart contract is no different than a script or predicate in that it is a piece of bytecode that is deployed to the blockchain via a [transaction](https://fuellabs.github.io/fuel-specs/master/protocol/tx_format). The main features of a smart contract that differentiate it from scripts or predicates are that it is _callable_ and _stateful_. Put another way, a smart contract is analogous to a deployed API with some database state.
|
6 | 6 | <!-- contract:example:end -->
|
7 | 7 |
|
8 |
| -The interface of a smart contract, also just called a contract, must be defined strictly with an [ABI declaration](#the-abi-declaration). See [this contract](../examples/wallet_smart_contract.md) for an example. |
| 8 | +The interface of a smart contract, also just called a contract, can be explicitly defined with an [ABI declaration](#the-abi-declaration) or implicitly with an [impl Self](#impl-self-contracts) item for the special type "Contract". See [this contract](../examples/wallet_smart_contract.md) for an example on using ABIs. |
9 | 9 |
|
10 | 10 | ## Syntax of a Smart Contract
|
11 | 11 |
|
12 |
| -As with any Sway program, the program starts with a declaration of what [program type](./index.md) it is. A contract must also either define or import an [ABI declaration](#the-abi-declaration) and implement it. |
| 12 | +As with any Sway program, the program starts with a declaration of what [program type](./index.md) it is. When using ABIs, a contract must either define or import an [ABI declaration](#the-abi-declaration) and implement it. |
13 | 13 |
|
14 | 14 | <!-- This section should explain best practices for ABIs -->
|
15 | 15 | <!-- ABI:example:start -->
|
@@ -100,3 +100,18 @@ Each special parameter is optional and assumes a default value when skipped:
|
100 | 100 | 1. The default value for `gas` is the context gas (i.e. the content of the special register `$cgas`). Refer to the [FuelVM specifications](https://fuellabs.github.io/fuel-specs/master/vm) for more information about context gas.
|
101 | 101 | 2. The default value for `coins` is 0.
|
102 | 102 | 3. The default value for `asset_id` is `b256::zero()`.
|
| 103 | + |
| 104 | +## Impl Self Contracts |
| 105 | + |
| 106 | +In some cases, it may be more convenient to avoid declaring an ABI and implement the contract directly, as shown in the example below. In this case, the compiler will automatically create an ABI |
| 107 | +named as the package containing the `impl Contract` item, and will insert each function inside the ABI. |
| 108 | + |
| 109 | +```sway |
| 110 | +{{#include ../../../../examples/wallet_smart_contract_self_impl/src/main.sw:abi_impl}} |
| 111 | +``` |
| 112 | + |
| 113 | +Without an ABI, there is no way for scripts and other contracts to use `abi(...)` and call this contract, but it can still be tested, as any other contract. The ABI name will be the "upper camel case" version of the package name containing the "impl Contract" item. `CONTRACT_ID` is a compiler special constant that references the contract being implemented in this file. |
| 114 | + |
| 115 | +```sway |
| 116 | +{{#include ../../../../examples/wallet_smart_contract_self_impl/src/main.sw:tests}} |
| 117 | +``` |
0 commit comments