Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Contract Quickstart

Icon LinkSmart Contract Quickstart

Getting started with Fuel as a smart contract developer is as simple as:

  1. Installing fuelup
  2. Generating a counter contract
  3. Building the contract
  4. Setting up a local wallet
  5. Deploying the contract

Icon LinkInstallation

To install the Fuel toolchain, you can use the fuelup-init script. This will install forc, forc-client, forc-fmt, forc-lsp, forc-wallet as well as fuel-core in ~/.fuelup/bin.

curl https://install.fuel.network | sh
Icon InfoCircle

Having problems? Visit the installation guide or post your question in our forum Icon Link.

If you're using VSCode, we recommend installing the Sway extension Icon Link.

Icon LinkAlready have fuelup installed?

If you already have fuelup installed, run the commands below to make sure you are on the most up-to-date toolchain.

fuelup self update
fuelup update
fuelup default latest

Icon LinkGenerating a counter contract

Run the command below to generate a counter contract in Sway:

forc template --template-name counter counter-contract

The contract will be in the src/main.sw file.

Here is the project that forc has initialized:

tree counter-contract
counter-contract
├── Forc.toml
└── src
    └── main.sw

1 directory, 2 files

forc.toml is the manifest file (similar to Cargo.toml for Cargo or package.json for Node) and defines project metadata such as the project name and dependencies.

Icon LinkBuilding the contract

To build a contract, move inside the counter-contract folder:

cd counter-contract

Next, run the forc build command:

forc build

Icon LinkSetting up a local wallet

The forc-wallet plugin is packaged alongside the default distributed toolchains when installed using fuelup, so you should already have this installed if you've followed the instructions above.

To initialize a new wallet with forc-wallet, you can run the command below:

forc wallet new

After typing in a password, be sure to save the mnemonic phrase that is output.

Next, create a new wallet account with:

forc wallet account new

With this, you'll get a fuel address that looks something like this: fuel1efz7lf36w9da9jekqzyuzqsfrqrlzwtt3j3clvemm6eru8fe9nvqj5kar8.

If you need to list your accounts, you can run the command below:

forc wallet accounts

You can get test funds using the faucet Icon Link.

Icon LinkDeploying the contract

To deploy the contract to the testnet, you can run:

forc deploy --testnet

The terminal will ask for the password of the wallet:

Please provide the password of your encrypted wallet vault at "~/.fuel/wallets/.wallet":

Once you have unlocked the wallet, the terminal will show a list of the accounts:

Account 0 -- fuel18caanqmumttfnm8qp0eq7u9yluydxtqmzuaqtzdjlsww5t2jmg9skutn8n:
  Asset ID                                                           Amount
  0000000000000000000000000000000000000000000000000000000000000000 499999940

Just below the list, you'll see this prompt:

Please provide the index of account to use for signing:

Then you'll enter the number of the account of preference and press Y when prompted to accept the transaction.

Finally, you will get back the network endpoint where the contract was deployed, a Contract ID and the block where the transaction was signed.

Icon LinkNext Steps

Ready to learn more? Check out the following resources: