Testing Contract with Rust

Can I test the contract only before deployment or after deployment is this function also available?

You can choose either option, but you still need the original ABI and the binary generated from compiling the contract. For interacting with a contract after its deployment, you should use the beta-5 provider and replace the LOCAL deployed contract as shown in this quickstart example with your own deployed contract id:

let id = Contract::load_from(
        "./out/debug/counter-contract.bin",
        LoadConfiguration::default(),
    )
    .unwrap()
    .deploy(&wallet, TxPolicies::default())
    .await
    .unwrap();

You can follow the steps provided here for further guidance:
Building and Testing Your Contract with Rust

when deploying the contract I used beta 4
how do I update or install beta 5?

It’s really easy to update your toolchain to beta-5 just follow these two steps here:

Toolchain Installation:

  1. To install Beta 5, run: fuelup toolchain install beta-5
  2. Set it as default with: fuelup default beta-5
1 Like

Do I need to add the address of my contract to this code (if so, where should I insert it)?
or do I just need to enter this code as it is now?

HI there @Voland
The code above won’t require your contract’s address, since it’s deploying a new one.
In fact, the previous code is giving you a contract ID that you can use for further testing.

I don’t recommend you to just copy and paste code, since we can’t assure that will work on your local environment. The snippet shown above is an example on how you can generate a new contract ID for testing, by using an abi file.

2 Likes