docs/src/deploying/index.md
There are two main ways of working with contracts in the SDK: deploying a contract with SDK or using the SDK to interact with existing contracts.
Once you've written a contract in Sway and compiled it with forc build, you'll have in your hands two important artifacts: the compiled binary file and the JSON ABI file.
Note: Read here for more on how to work with Sway.
Below is how you can deploy your contracts using the SDK. For more details about each component in this process, read The abigen macro, The FuelVM binary file, and The JSON ABI file.
<!-- This section should explain how to load and deploy a contract --> <!-- deploy:example:start -->First, the Contract::load_from function is used to load a contract binary with a LoadConfiguration. If you are only interested in a single instance of your contract, use the default configuration: LoadConfiguration::default(). After the contract binary is loaded, you can use the deploy() method to deploy the contract to the blockchain.
{{#include ../../../examples/contracts/src/lib.rs:deploy_contract}}
Alternatively, you can use LoadConfiguration to configure how the contract is loaded. LoadConfiguration let's you:
Salt to get a new contract_idNote: The next section will give more information on how
configurablescan be used.
Additionally, you can set custom TxParameters when deploying the loaded contract.
{{#include ../../../examples/contracts/src/lib.rs:deploy_with_parameters}}
After the contract is deployed, you can use the contract's methods like this:
{{#include ../../../examples/contracts/src/lib.rs:use_deployed_contract}}
Note: When redeploying an existing
Contract, ensure that you initialize it with a unique salt to prevent deployment failures caused by a contract ID collision. To accomplish this, utilize thewith_saltmethod to clone the existingContractwith a new salt.