SmartDeploy
A framework for publishing, developing, deploying, and upgrading Soroban smart contracts.
You can think of it as a package manager for Smart Contracts.
Consider the following contract:
use ;
;
core_riff!;
The last line smartdeploy_sdk::core_riff
ensures that the contract is redeployable.
After building you can publish and deploy the contract.
Now let's say that we have a second contract b
use ;
import_contract!;
;
core_riff!;
We can "install" contract_a and then reference it to create a client:
Now the import_contract
macro let's you import the contract the same way you would depend on a normal rust depenedency.
!;
...
new.add
import_contract
Now build the contract since contract_a was added to target/smartdeploy/contract_a/index.wasm
Next after publishing and deploying contract_b
, let's take this a step further and create a third contract.
use ;
import_contract!;
import_contract!;
;
const KEY: &Symbol = &symbol_short!;
core_riff!;
We'll need to install contract_b
as well
This also adds a target/smartdeploy/contract_b/contract_id.txt
file with the contract id of the contract.
With the contract's id we can create client directly without the need to track down the contract id
new
And we can address the address directly
address
This is super handy for oracle contracts or any contract that you want developers to call in their contracts.
You'll also notice that this contract has an init method. Currently with the soroban CLI you cannot deploy and invoke a contract in one step. You can with smartdeploy!
Just like the awesome feature of the soroban CLI, smartdeploy generates a CLI for the contract that is to be deployed. You can access the possible methods with --help
smartdeploy deploy --published-name contract_c --deployed-name c3pO -- --help
Usage: c3pO [COMMAND]
Commands:
add_with
owner_get Returns the owner of the contract
owner_set Sets the owner of the contract. If one already set it transfers it to the new owner, if signed by owner.
redeploy Redeploy the contract to a wasm hash
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
Now we can call the contract with smartdeploy call
and leave off the --y
argument, which should then default to 41
.
This calls creates a cross contract call to contract_b
and then it calls contract_a
. All without having to manually reference any contract ids!
Smartdeploy is also a Dapp!
Check it out here: launch.smartdeploy.dev.
It current lets you see all published contracts:
Deploy them:
And see all deployed contracts
Coming soon:
- Autogenerated init method input forms for when deploying like you can with the CLI.
- Autogenerated forms for any deployed contract's methods (not just deployed smartdeploy)!
- Indexing will let dapp let you quickly search about contracts like crates.io.
Getting started
The key idea behind smartdeploy is that contract should be redeployable and maintainable. To solve this smartdeploy allows for publishing contract binaries and set of primitives to ensure that contracts can be redeployed.
smartdeploy-sdk
First you need to add smartdeploy-sdk to your contract's Cargo.toml
soroban-cli
Currently smartdeploy relies on yet unstable version of the CLI
Next you need to add the following line to your contract:
!;
core_riff
This adds three methods to your contract: owner_set
, owner_get
, and redeploy
. After deploying your contract you must call owner_set
, with your account so that you can call redploy
, providing the hash of an installed contract (see next section for more info).
However, while you are developing this can be tedious so there is also dev_deploy
.
!;
dev_deploy
This adds the method dev_deploy
to your contract. This let's you redeploy your contract with just a wasm binary. However, it is not meant to be used on a public network as anyone can call it.
So assuming you choose the later option, after initially deploying your contract, you'll get a contract id, e.g.CA5YTYGCKWYJW7P3JNSMVKV2HRN4TOFMZ2VW4AQ5WQS4P3BGHNOU3PPX
.
Then after making changes to your contract you can redeploy with the following:
This makes use of the new --<arg>-file-path
argument that is added to the contract's generated CLI, allowing you to pass a file as the input to the contract's method. --fee
is also used because the default is 100, which is probably not enough for the cost of including the bytes of your contract.
The other core idea behind smartdeploy is that contract can be published so that anyone can deploy an instance of it. This means that this fee is only paid by the contract publisher.
Note you can also use a .env
file in the same directory where you call invoke
to set CLI arguments. For example,
SOROBAN_NETWORK=standalone
SOROBAN_ACCOUNT=default
SOROBAN_FEE=1000000
Uses Loam-SDK
Smartdeploy CLI
Install
cargo install smartdeploy-cli
Currently the smartdeploy CLI has a install
and call
subcommand which lets you use a deployed contract's name when invoking it.
Can list out deployed_contracts