Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Managing Deployed Contracts

Icon LinkManaging Deployed Contracts

To interact with a deployed contract using the SDK without redeploying it, you only need the contract ID and its JSON ABI. This allows you to bypass the deployment setup.

Icon LinkContract ID

The contractId property from the Contract Icon Link class is of type AbstractAddress Icon Link, an abstract class that is exclusively extended by the Address Icon Link class.

The Address Icon Link class wraps all methods from the AbstractAddress Icon Link class and adds a single property: bech32Address. This property is a string encoded in Bech32 format, recognizable by the human-readable prefix fuel followed by the separator 1.

Icon InfoCircle

[!NOTE] Note Bech32 addresses like fuel1.. are now deprecated; please switch to B256 format, for more details see here Icon Link.

When you log the contractId property of an instantiated Contract using console.log, the output appears as follows:

  Address {
    bech32Address: 'fuel1e5tdjlzufcvwut5dvs5yglweepmrevpnvuvt2djj6pyl3mygkwaq8m7f20'
  }

If you have already an instantiated and deployed contract in hands you can create another contract instance simply by using the contractId property and the contract JSON ABI:

const deployedEchoContract = new Contract(contractId, abi, wallet);
 
const { value: echoed10 } = await deployedEchoContract.functions
  .echo_u8(10)
  .simulate();
// value 10

The previous example assumes that you have a Contract Icon Link instance at hand. However, some Fuel tools and Sway use the b256 type format, a hex-encoded string-like type, for contract IDs.

You might have this format instead, for example, if you have deployed your contract with forc deploy.

The process of instantiating a Contract Icon Link remains the same when using a contract ID of type b256:

const contract = new Contract(b256, abi, wallet);
 
const { value: echoed50 } = await contract.functions.echo_u8(50).simulate();