Interacting with contracts

If you already have a deployed contract and want to call its methods using the SDK, but without deploying it again, all you need is the contract ID of your deployed contract. You can skip the whole deployment setup and call ::new(contract_id, wallet) directly. For example:

                name = "MyContract",
                // Replace with your contract ABI.json path
                abi =
            let wallet_original = launch_provider_and_get_wallet().await;

            let wallet = wallet_original.clone();
            // Your bech32m encoded contract ID.
            let contract_id: Bech32ContractId =
                    .expect("Invalid ID");

            let connected_contract_instance = MyContract::new(contract_id, wallet);
            // You can now use the `connected_contract_instance` just as you did above!

The above example assumes that your contract id string is encoded in the bech32m format. You can recognize it by the human-readable-part "fuel" followed by the separator "1". However, when using other Fuel tools, you might end up with a hex-encoded contract id string. In that case, you can create your contract instance as follows:

            let contract_id: ContractId =
                    .expect("Invalid ID");
            let connected_contract_instance = MyContract::new(contract_id.into(), wallet);

You can learn more about the Fuel SDK bech32 types here.