V12 Docs
Launch Spark
  • Overview
  • Trade
    • πŸš€ Getting Started as a Trader
      • Wallet Setup
        • Fuel Wallet
        • Fuelet Wallet
        • Ethereum Wallets
      • Bridging Assets Using the Fuel Bridge
      • Deposit Assets using Testnet Faucet
      • Creating Orders
        • Order Book
          • Limit Order
          • Market Order
          • Cancelling an order
        • Swap
      • Fee Structure
  • Provide Liquidity
    • πŸ“ˆ Getting Started as a Market Maker
      • Market Maker Incentive Program
      • Fee Structure
      • SLAs for Market Makers
  • Build
    • πŸ‘©β€πŸ’» Getting Started as a Developer
      • Rust Integration Guide
        • Fuel and V12 Market Setup Tutorial
        • V12 Rust SDK
      • TypeScript SDK
      • Data Indexing
        • Envio Indexer Setup Guide
        • Indexer Queries
        • Connecting to the indexer via WebSocket
      • Order Book Technical Reference
  • Security
    • πŸ” Audit Report
  • More
    • πŸ—οΈ V12 Architecture Overview
    • πŸ† Point Rewards Program
    • βš–οΈ Terms
  • Community
    • Twitter
    • Telegram
    • Discord
    • GitHub
Powered by GitBook
On this page
  • Step 1: Install the Fuel Toolchain
  • Step 2: Install the V12 Rust Packages
  • Step 3: Set Up Your `.env` File
  • Step 4: Call the Spark Market Contract
  • Additional Resources
  1. Build
  2. πŸ‘©β€πŸ’» Getting Started as a Developer
  3. Rust Integration Guide

Fuel and V12 Market Setup Tutorial

PreviousRust Integration GuideNextV12 Rust SDK

Last updated 4 months ago

Step 1: Install the Fuel Toolchain

First, install the Fuel toolchain by following the instructions provided in the Fuel documentation:

Step 2: Install the V12 Rust Packages

Next, create a new directory for your project and initialize a new Rust package using cargo init. You’ll also need to install the necessary V12 and environment packages by running the following commands:

cargo init
cargo add tokio
cargo add env
cargo add dotenv
cargo add fuels
cargo add spark-market-sdk
cargo add spark-registry-sdk

Step 3: Set Up Your `.env` File

Create a .env file in the root of your project and add the following environment variables:

# Mnemonic phrase 
MNEMONIC="your mnemonic here"

# Spark Contracts
MARKET_REGISTRY="0x194987ad2314d2de50646078ac1841f00b2dffda863a7d3dd421d220eb83d019"
BTC_USDC_CONTRACT_ID="0x7b88385ae73dd3ccc62012e7a52cddd05c7e82ad54a5df721dfa0c1f8b5998f0"
ETH_USDC_CONTRACT_ID="0xc18094a283193c9b4726d2f644ed07ec9806bbe60a0688d45bffb26c379c1428"

# Asset IDs
BTC_ID="0x38e4ca985b22625fff93205e997bfc5cc8453a953da638ad297ca60a9f2600bc"
ETH_ID="0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
USDC_ID="0x336b7c06352a4b736ff6f688ba6885788b3df16e136e95310ade51aa32dc6f05"

Step 4: Call the Spark Market Contract

Now, let’s call the Spark Market contract to retrieve the matcher and protocol fees. Here's an example code to achieve that:

use dotenv::dotenv;
use std::env;

use fuels::{accounts::provider::Provider, accounts::wallet::WalletUnlocked, types::ContractId};
use std::str::FromStr;
use std::error::Error;

use spark_market_sdk::SparkMarketContract;

pub fn format_value_with_decimals(value: u64, decimals: u32) -> u64 {
    value * 10u64.pow(decimals)
}

pub fn format_to_readable_value(value: u64, decimals: u32) -> f64 {
    value as f64 / 10u64.pow(decimals) as f64
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    dotenv().ok();

    // Environment variables
    let mnemonic = env::var("MNEMONIC")?;
    let contract_id = env::var("BTC_USDC_CONTRACT_ID")?;

    // Connect to provider
    let provider = Provider::connect("testnet.fuel.network").await?;

    let main_wallet =
        WalletUnlocked::new_from_mnemonic_phrase(&mnemonic, Some(provider.clone())).unwrap();
    let contract_id = ContractId::from_str(&contract_id).unwrap();
    let market = SparkMarketContract::new(contract_id.clone(), main_wallet.clone()).await;

    // Getting Fees from Spark Market
    let matcher_fee = market.matcher_fee().await?.value;
    println!("matcher_fee: {:?}", matcher_fee);

    let protocol_fee = market.protocol_fee().await?.value;
    println!("protocol fee: {:?}", protocol_fee);

    Ok(())
}

Additional Resources

  • V12 Rust SDK Packages:

Note: Be sure to check for the latest contract deployment addresses .

Example Use Cases: Find more examples, including opening orders, batch operations, and canceling orders, by exploring the .

Install the Fuel Toolchain
here
Spark Rust SDK Examples
spark-market-sdk
spark-registry-sdk