Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A modular toolkit for smart-contracts on XRPL built in Go

Notifications You must be signed in to change notification settings

XRPL-Commons/Bedrock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

27 Commits

Repository files navigation

Bedrock - XRPL Smart Contract CLI

The foundation for XRPL smart contract development

Bedrock is a developer tool for building, deploying, and interacting with XRPL smart contracts written in Rust. Think Foundry, but for XRPL.

Features

  • 🏗️ Build - Compile Rust smart contracts to WASM
  • 🚀 Deploy - Smart deployment with auto-build and ABI generation
  • 📞 Call - Interact with deployed contracts
  • 🔧 Local Node - Manage local XRPL test network
  • 📝 ABI Generation - Automatic ABI extraction from Rust code
  • Fast - Embedded JS modules with intelligent caching

Requirements

Before installing Bedrock, ensure you have:

  • Go (1.21 or later) - For building/installing Bedrock
  • Node.js (18 or later) - For XRPL transaction handling
  • Rust - For compiling smart contracts
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Docker (optional) - For running local XRPL node

Verify Installation

go version # Should show 1.21+
node --version # Should show v18+
rustc --version # Should show 1.70+
cargo --version

Installation

Install from Source

# Clone the repository
git clone https://github.com/xrpl-bedrock/bedrock.git
cd bedrock
# Build and install
go build -o bedrock cmd/bedrock/main.go
sudo mv bedrock /usr/local/bin/
# Verify installation
bedrock --help

First Run Setup

On first run, Bedrock will automatically:

  1. Install JavaScript dependencies (XRPL libraries)
  2. Cache them in ~/.cache/bedrock/modules (Linux/macOS)
  3. You'll see: ⚡ First run detected - installing JavaScript dependencies...

This only happens once. Subsequent runs are instant!

Quick Start

1. Initialize a New Project

bedrock init my-contract
cd my-contract

This creates:

my-contract/
├── bedrock.toml # Project configuration
├── contract/
│ └── src/
│ └── lib.rs # Your smart contract
└── abi.json # Generated ABI (after build)

2. Build Your Contract

bedrock build

This compiles your Rust contract to WASM in release mode.

3. Start Local Node (Optional)

bedrock node start

Starts a local XRPL test network in Docker at:

  • WebSocket: ws://localhost:6006
  • Faucet: http://localhost:8080/faucet

4. Deploy Your Contract

# Deploy to local node
bedrock deploy --network local
# Deploy to alphanet (testnet)
bedrock deploy --network alphanet
# Deploy with specific wallet
bedrock deploy --wallet sXXX...

Smart Deployment automatically:

  1. ✅ Builds contract in release mode (if needed)
  2. ✅ Generates ABI (if needed)
  3. ✅ Deploys to network

5. Call Contract Functions

# Call without parameters
bedrock call rContract123... hello --wallet sXXX...
# Call with parameters
bedrock call rContract123... transfer \
 --wallet sXXX... \
 --params '{"to":"rRecipient...","amount":1000}'
# Use parameters from file
bedrock call rContract123... register \
 --wallet sXXX... \
 --params-file params.json

Commands

Core Workflow

Command Description
bedrock init [name] Initialize new project
bedrock build Build contract (release mode)
bedrock deploy Deploy with auto-build & ABI
bedrock call <contract> <fn> Call contract function
bedrock node <start|stop|status> Manage local node

Build Options

bedrock build # Build in release mode (default)
bedrock build --debug # Build in debug mode (faster, larger)

Deploy Options

bedrock deploy # Smart deploy (auto-build + ABI)
bedrock deploy --skip-build # Skip building
bedrock deploy --skip-abi # Skip ABI generation
bedrock deploy --network alphanet # Deploy to alphanet
bedrock deploy --wallet sXXX... # Use specific wallet

Call Options

bedrock call <contract> <function> \
 --wallet sXXX... # Wallet seed (required)
 --network alphanet # Network (default: alphanet)
 --params '{"key":"value"}' # JSON parameters
 --params-file params.json # Parameters from file
 --gas 1000000 # Computation allowance
 --fee 1000000 # Transaction fee (drops)

Node Management

bedrock node start # Start local XRPL node
bedrock node stop # Stop local node
bedrock node status # Check if running
bedrock node logs # View node logs (coming soon)

Project Configuration

Edit bedrock.toml to configure your project:

[project]
name = "my-contract"
version = "0.1.0"
[build]
source = "contract/src/lib.rs"
target = "wasm32-unknown-unknown"
[networks.local]
url = "ws://localhost:6006"
faucet_url = "http://localhost:8080/faucet"
[networks.alphanet]
url = "wss://alphanet.nerdnest.xyz"
faucet_url = "https://alphanet.faucet.nerdnest.xyz/accounts"

Writing Smart Contracts

Basic Contract Structure

use xrpl_wasm::*;
/// @xrpl-function hello
/// @xrpl-param name: VL - User name
/// @xrpl-return UINT64 - Success code
#[wasm_export]
fn hello(name: Vec<u8>) -> u64 {
 let _ = trace("Hello from XRPL!");
 0 // Success
}

ABI Annotations

Bedrock automatically generates ABIs from JSDoc-style comments:

/// @xrpl-function transfer
/// @xrpl-param to: ACCOUNT - Recipient address
/// @xrpl-param amount: UINT64 - Amount to transfer
/// @xrpl-return UINT64 - Success code
#[wasm_export]
fn transfer(to: Vec<u8>, amount: u64) -> u64 {
 // Implementation
 0
}

Supported parameter types:

  • UINT8, UINT16, UINT32, UINT64, UINT128, UINT256
  • VL (variable length bytes/string)
  • ACCOUNT (XRPL address)
  • AMOUNT (XRP drops or IOU)
  • CURRENCY, ISSUE

Development Workflow

Local Development Loop

# Terminal 1: Start local node
bedrock node start
# Terminal 2: Develop and test
bedrock build # Build contract
bedrock deploy --local # Deploy to local node
bedrock call rXXX... hello --wallet sXXX... # Test function
# Make changes to contract...
bedrock deploy --local # Redeploy (auto-rebuilds)

Deploying to Testnet

# 1. Build and deploy to alphanet
bedrock deploy --network alphanet
# Save the output:
# Wallet Seed: sXXX...
# Contract Account: rContract123...
# 2. Call your contract
bedrock call rContract123... myFunction \
 --wallet sXXX... \
 --network alphanet

Architecture

Module System

Bedrock uses embedded JavaScript modules for XRPL transaction handling:

~/.cache/bedrock/modules/
├── deploy.js # Deployment module
├── call.js # Contract calling module
├── package.json # Dependencies (@transia/xrpl)
└── node_modules/ # Installed on first run

Why JavaScript Modules?

XRPL smart contracts are in alpha, and the only stable tooling is in JavaScript. Bedrock embeds these modules and will migrate to pure Go as XRPL tooling matures.

Cache Management

  • First run: Installs npm dependencies (~10-15 seconds)
  • Subsequent runs: Uses cached modules (instant)
  • Updates: Automatic reinstall when CLI is updated (version detection via SHA256)
  • Manual cleanup: rm -rf ~/.cache/bedrock

Troubleshooting

Dependencies Not Installing

# Check Node.js version
node --version # Should be 18+
# Manually install dependencies
cd ~/.cache/bedrock/modules
npm install

WASM Build Fails

# Add wasm32 target
rustup target add wasm32-unknown-unknown
# Update Rust
rustup update

Local Node Won't Start

# Check Docker is running
docker ps
# View Docker logs
docker logs bedrock-xrpl-node
# Restart Docker daemon

Config Not Found

# Make sure you're in a Bedrock project directory
ls bedrock.toml
# Or initialize a new project
bedrock init my-project

Contributing

Contributions are welcome! Please check out:

Roadmap

  • Smart contract compilation (Rust → WASM)
  • Automatic ABI generation
  • Contract deployment
  • Contract function calling
  • Local node management
  • Contract testing framework
  • Wallet management (bedrock wallet)
  • Contract verification
  • TypeScript SDK generation
  • Watch mode for development
  • Migration to pure Go (when XRPL tooling matures)

License

MIT License - See LICENSE for details

Resources


Built with ⚡ by the Bedrock team

About

A modular toolkit for smart-contracts on XRPL built in Go

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

AltStyle によって変換されたページ (->オリジナル) /