Icon LinkDefining the Program Type

The first line of the file is specifically reserved to inform the compiler whether we are writing a contract, script, predicate, or library. To designate the file as a contract, use the contract keyword.

contract;

Icon LinkImports

The Sway standard library Icon Link provides several utility types and methods we can use in our contract. To import a library, you can use the use keyword and ::, also called a namespace qualifier, to chain library names like this:

// imports the msg_sender function from the std library
use std::auth::msg_sender;

You can also group together imports using curly brackets:

use std::{
	auth::msg_sender,
	storage::StorageVec,
}

For this contract, here is what needs to be imported:

use std::{
	auth::msg_sender,
	call_frames::msg_asset_id,
	constants::BASE_ASSET_ID,
	context::{
		msg_amount,
		this_balance,
	},
	token::transfer,
};

We'll go through what each of these imports does as we use them in the next steps.

Was this page helpful?

Icon ListDetailsOn this page