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.

Last updated