♠️
RACE Protocol
NFT PresaleDiscord
  • ❤️Official Docs & Links
  • ⏳Progress Overview
  • RACE Protocol
    • 🏗️System Architecture
      • Components
      • On-chain Accounts
      • Synchronization
      • Randomization
      • Payment
    • 🎲Game Development
      • Game Handler
      • Effect
      • Event Handling
      • Race API
        • Arweave Integration
      • Race JS SDK
        • Installation and Setup
        • Key Components
          • AppClient
          • SubClient
          • Events
          • Game Context
          • Decryption Cache
        • Advanced Features
          • Getting Revealed Knowledge
          • Exiting and Detaching
          • Submitting Messages
          • Sub-game Interaction
        • Best Practices
        • API Reference
        • Troubleshooting
    • 🧪Testing
      • Race Test Kit
      • Unit Testing
      • Integration Testing
      • Additional Considerations
    • 🧱Modules & Features
      • Encryption Methods
      • Command-line Tools
      • Configuration Options
      • Blockchain Transport Implementations
    • 📃Smart Contract
      • Solana Program
    • 🔦Examples and Use Cases
      • Draw Card Game
      • Raffle Game
      • Other Examples
  • RACE Games
    • ♠️RACE Poker app
      • 🎮Start playing in minutes
        • 💰Cash and sit-n-go
        • 🏆Tournaments
      • 🎨Workshop
        • 🏆Create cash games
        • 🏨Create tourneys
      • 💡Concept introduction
      • 🏗️System architecture
      • 👾Game Flow
      • 🎲Cards shuffling
      • ☎️Communication
      • 🔐Key sharing/decryption
      • 💱Cash flow structure
    • ⚡Solfast
      • 🎲Game modes
  • RACE RESEARCH
    • 👾No-Code Development
      • Brainstorming
      • Implementation Approach
      • Project Status
    • 0️⃣Zero-Knowledge Proofs
      • Brainstorming
      • Integration steps
        • Verifiable Randomness Generation
        • Private Game State Updates
        • Verifiable Settlements
        • Private Player Actions
      • Project Status
    • 🛡️Security Audit Report
      • Executive summary
        • Introduction to Race Protocol
        • Audit Methodology
      • Findings
        • Smart Contract Security
        • WebAssembly Security
        • Client-side Security (Race SDK)
        • Server-side Security
        • Randomization and Encryption
        • On-chain Account Management
        • Synchronization Mechanisms
        • Payment Handling
      • Recommendations
      • Conclusion
  • RACE DAO
    • 😎About
    • 🫂Community
    • 🖼️NFT Collection [!]
Powered by GitBook
On this page
  • Prerequisites (Additional)
  • Publishing to Arweave
  1. RACE Protocol
  2. Game Development
  3. Race API

Arweave Integration

This section expands upon the previous guide to include steps on how to publish your WASM bundle to Arweave using the Race Protocol API.

Prerequisites (Additional)

  • Arweave JWK keyfile: You'll need an Arweave JWK keyfile to interact with the Arweave network. You can create one using the Arweave CLI or other tools.

  • race-storage dependency: Add the race-storage crate as a dependency in your project's Cargo.toml file. This crate provides utilities for uploading data to Arweave.

Publishing to Arweave

Follow these steps to publish your WASM bundle to Arweave:

1. Build the WASM bundle:

  • Use cargo build -r -p <your_game_crate> --target wasm32-unknown-unknown to build your game logic into a WASM bundle.

2. Create an Arweave client:

// Rust code
use race_storage::arweave::Arweave;

let arweave = Arweave::try_new("path/to/arweave_keyfile.json")?;

Replace "path/to/arweave_keyfile.json" with the actual path to your Arweave JWK keyfile.

3. Upload the WASM bundle:

// Rust code
let wasm_data = std::fs::read("path/to/your_game.wasm")?;
let bundle_addr = arweave.upload_file(wasm_data, Some("application/wasm")).await?;

Replace "path/to/your_game.wasm" with the path to your built WASM bundle. The upload_file function takes the data to upload and an optional content type. In this case, we specify "application/wasm" as the content type.

The bundle_addr variable will now contain the Arweave address of your uploaded WASM bundle.

4. (Optional) Create and upload metadata:

  • You can optionally create a metadata.json file that provides additional information about your game bundle, such as its name, description, and creators.

  • Use the race_storage::metadata module to create the metadata object and serialize it to JSON.

  • Upload the metadata.json file to Arweave using the arweave.upload_file function.

5. Use the bundle address:

  • You can now use the bundle_addr in your Race Protocol interactions, such as when creating a game account on the blockchain. The Transactor and validator servers will use this address to fetch the WASM bundle from Arweave when needed.

Example Code

Here's an example code snippet demonstrating the Arweave upload process:

// Rust code
use race_storage::arweave::Arweave;

async fn publish_to_arweave(wasm_path: &str, keyfile_path: &str) -> Result<String> {
    let arweave = Arweave::try_new(keyfile_path)?;
    let wasm_data = std::fs::read(wasm_path)?;
    let bundle_addr = arweave.upload_file(wasm_data, Some("application/wasm")).await?;
    Ok(bundle_addr)
}

This function takes the path to the WASM bundle and the Arweave keyfile as arguments and returns the Arweave address of the uploaded bundle.

Additional Notes

  • Ensure you have sufficient AR tokens in your Arweave wallet to cover the upload costs.

  • Consider creating and uploading a metadata.json file to provide additional information about your game bundle.

  • You can use the Arweave CLI or other tools to manage your Arweave wallet and keyfile.

By following these steps and utilizing the Race Protocol API, you can seamlessly publish your game's WASM bundle to Arweave, making it accessible to the Transactor and validator servers for execution and ensuring a decentralized and transparent gaming experience.

PreviousRace APINextRace JS SDK

Last updated 1 year ago

🎲