You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rewrite deploy-contract guide's deployer example for the current constructor-based pattern (#2696)
### What
Update the deployer guide's contract code, CLI commands, and example link to match the current constructor-based deployer contract instead of the old init-function pattern.
### Why
The deployer contract's actual current implementation takes an administrator at construction time and uses `deploy_v2`, so the old `init_fn`/`init_args` example and CLI flags shown here no longer match what a reader would find in the real example or be able to run.
The deployer contract provides a mechanism to deploy other contracts in a secure and deterministic manner. It ensures that the deployment is authorized by the specified deployer address and supports atomic initialization of the newly deployed contract. This guarantees that the contract is properly initialized immediately after deployment, preventing any potential issues with uninitialized contracts.
114
+
The deployer contract provides a mechanism to deploy other contracts in a secure and deterministic manner. It stores an administrator address at construction time and requires that administrator's authorization for every deployment. It also supports atomic initialization of the newly deployed contract via constructor arguments. This guarantees that the contract is properly initialized immediately after deployment, preventing any potential issues with uninitialized contracts.
116
115
117
116
### Function breakdown
118
117
119
118
-`env: Env`: The Env object represents the current contract execution environment. It provides methods to interact with the blockchain and other contracts, as well as perform various operations.
120
-
-`deployer: Address`: The Address of the entity that is requesting the contract deployment. This address will be used to authorize the deployment.
119
+
-`admin: Address`: The Address of the administrator, provided to the `__constructor` function and stored for later use. Only this address can authorize deployments.
121
120
-`wasm_hash: BytesN<32>`: The hash of the Wasm bytecode of the contract to be deployed and must already be installed and on the ledger. This hash is used to uniquely identify the contract's code.
122
-
-`salt: BytesN<32>`: A unique value used to derive the address of the deployed contract. The same combination of deployer address and salt will always produce the same deployed contract address, ensuring deterministic contract addresses.
123
-
-`init_fn: Symbol`: The name of the initialization function to be called on the newly deployed contract.
124
-
-`init_args: Vec<Val>`: A vector of arguments, specified as `{type: value}` objects, to be passed to the initialization function of the deployed contract.
121
+
-`salt: BytesN<32>`: A unique value used to derive the address of the deployed contract. The same combination of the `Deployer` contract's address and salt will always produce the same deployed contract address, ensuring deterministic contract addresses.
122
+
-`constructor_args: Vec<Val>`: A vector of arguments, specified as `{type: value}` objects, to be passed to the constructor of the deployed contract.
The function checks if the `deployer` address is the same as the current contract’s address. If it is not, it requires authorization from the deployer address to ensure that the deployer has permitted this deployment.
131
+
The function loads the administrator address that was stored during construction and requires its authorization, ensuring that only the administrator can trigger a deployment.
- Uses the `env.deployer()` method to create a deployer object.
144
-
-`with_address(deployer, salt)` specifies the deployer address and the salt to derive the new contract’s address.
145
-
-`deploy(wasm_hash)` deploys the contract using the provided Wasm bytecode hash and returns the address of the newly deployed contract.
141
+
-`with_address(env.current_contract_address(), salt)` specifies that the deployed contract's address is derived from the `Deployer` contract's own address and the given salt.
142
+
-`deploy_v2(wasm_hash, constructor_args)` deploys the contract using the provided Wasm bytecode hash, invokes its constructor with `constructor_args`, and returns the address of the newly deployed contract.
- Invokes the specified initialization function (`init_fn`) on the newly deployed contract (`deployed_address`), passing the provided initialization arguments (`init_args`).
152
-
- The result of this function call is stored in `res`.
153
-
154
-
```rust
155
-
(deployed_address, res)
156
-
```
157
-
158
-
Returns a tuple containing the address of the newly deployed contract and the result of the initialization function.
148
+
Returns the address of the newly deployed contract.
Before deploying the test contract with the deployer, install the test contract Wasm using the `install` command. The `install` command will print out the hash derived from the Wasm file which should be used by the deployer.
170
+
Before deploying the test contract with the deployer, install the test contract Wasm using the `upload` command. The `upload` command will print out the hash derived from the Wasm file which should be used by the deployer.
181
171
182
172
```sh
183
173
stellar contract upload \
@@ -192,18 +182,19 @@ When deploying a smart contract to the network, you must specify an identity tha
192
182
193
183
The command prints out the hash as hex. It will look something like `6bc6d975ef99c057231481c40f69f4c2a8a89ac56e8826ef0378f8e5c6abc4be`.
194
184
195
-
We also need to deploy the `Deployer` contract:
185
+
We also need to deploy the `Deployer` contract. Since the `Deployer` contract's `__constructor` function requires an administrator address, we provide the `alice`[identity] as the `--admin` argument. Create and provide your own identity, where necessary.
This will return the deployer address. For example: `CDKYZMA3OXR54YAHOQ5D4EWDFDT3ZNKKRYKQT7MGPWH22ZVD2DX2BJID`.
205
196
206
-
Then the deployer contract may be invoked with the Wasm hash value above.
197
+
Then the deployer contract may be invoked with the Wasm hash value above. The `constructor_args` are passed through to the constructor of the deployed contract, so they are used here to set the initial `value` to `8`.
The deployer contract invocation will return the Contract address (For example: `CCTVFX6BFTQHTGAHA5TY4YZQJRUKRE2RRNUTGVBNKE3PJF5C7CI53APY`) of the newly deployed test contract.
0 commit comments