Prerequisites
Before starting, make sure to set up your development environment.Creating the contract
Create a smart contract with thecargo near scaffolding tool by following its instructions:

How bidding works
The contract insrc/lib.rs stores the highest bid and the auction’s end time. Its bid method accepts a deposit, checks that the auction is still open and the new bid is higher, then records the bid and refunds the previous bidder:
lib.rs
Test the contract locally
The project includes unit tests and sandbox tests. The sandbox tests build the contract and test it in a local Sandbox, that allows you to simulate a full NEAR environment locally without needing to create a testnet account or use real tokens.tests/test_basics.rs
tests/test_basics.rs
tests/test_basics.rs
tests/test_basics.rs
tests/test_basics.rs
tests/test_basics.rs
cargo test throughout development to check these interactions locally. Learn more about unit tests and sandbox tests.
Deploy and initialize on testnet
When you are ready to make the contract available to others, build it and deploy it to a testnet account. Testnet uses test tokens with no real value.Build and create an account
From theauction directory, build the contract and create an account to host it. Replace your-auction.testnet with your desired account name:
Got an error on Windows?
Got an error on Windows?
When working in
WSL—or another headless Linux environment—you might encounter issues creating an account because the CLI tries to save keys to the system keychain.In such cases, you can try the following command to create the account:Deploy and initialize the auction
The contract’sinit function sets the auction end time and the auctioneer who receives the winning bid. Here, we set the end time to five minutes from now, in nanoseconds, and use the contract account as the auctioneer. You can set AUCTIONEER_ID to another existing testnet account if you prefer.
Deploy and initialize in the same transaction so the auction is ready to use as soon as it is deployed:
Try placing a bid
To try the auction through the CLI, create a bidder account and place a bid before the five-minute auction ends. Replaceyour-bidder.testnet with your desired account name:
"10000000000000000000000" yoctoNEAR, equal to 0.01 NEAR.
That’s it!
You can now interact with the contract through a frontend or call its functions directly using the CLI.Frequently Asked Questions
What about mainnet?
What about mainnet?
Once your contract is ready for release, follow the deployment guide to deploy to mainnet.
How much does it cost to deploy?
How much does it cost to deploy?
The cost of deploying a contract depends on its size: approximately 1 Ⓝ per 100 KB.
Can I update a contract after deploying?
Can I update a contract after deploying?
Yes. Redeploy with
near deploy <account> <wasm-file>. The account stays the same, and the code is updated.How do I test without deploying?
How do I test without deploying?
Run
cargo test from your project directory. The sandbox tests handle local accounts and contract setup for you, so you can test the contract without a testnet account.Which SDK should I use to write smart contracts?
Which SDK should I use to write smart contracts?
Use near-sdk-rs, NEAR’s only official smart-contract SDK. It provides the Rust APIs used throughout this guide.
Moving forward
Create a Frontend
Check the auction frontend tutorial to learn how to build a simple web app that interacts with the auction contract.
Extend the Contract
Follow the auction NFT tutorial to award the highest bidder a Non-Fungible Token (NFT) and allow users to bid using Fungible Tokens (FT).
Learn More about the SDK
Check our Anatomy of a Contract page to understand the different components that make up a NEAR smart contract.