Getting started with Fuel as a smart contract developer is as simple as:
fuelup 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 | shHaving problems? Visit the installation guide or post your question in our forum .
If you're using VSCode, we recommend installing the Sway extension .
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 latestRun the command below to generate a counter contract in Sway:
forc new counter-contract The contract will be in the src/main.sw file.
Here is the project that forc has initialized:
tree counter-contractcounter-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.
To build a contract, move inside the counter-contract folder:
cd counter-contract Copy and paste the code below into your src/main.sw file
contract;
storage {
counter: u64 = 0,
}
abi Counter {
#[storage(read, write)]
fn increment();
#[storage(read)]
fn count() -> u64;
}
impl Counter for Contract {
#[storage(read)]
fn count() -> u64 {
storage.counter.read()
}
#[storage(read, write)]
fn increment() {
let incremented = storage.counter.read() + 1;
storage.counter.write(incremented);
}
} Next, run the forc build command:
forc build 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 newAfter 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 accountsYou can get test funds using the faucet .
To deploy the contract to the testnet, you can run:
forc deploy --testnetThe 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 499999940Just 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.
Ready to learn more? Check out the following resources: