ElderJS is a JavaScript library designed to enable front-end integration for Rollapps connected to the Elder Ecosystem. It provides tools to interact with Ethereum and Cosmos-based wallets, facilitating transaction creation, signing, and broadcasting within the Elder framework.
GitHub access for Elder is currently limited to early partner projects and may not be available to everyone. The documentation may be outdated due to rapid development.

Features

  • Ethereum Wallet Support: Create, sign, and broadcast transactions using Ethereum-based keys
  • Cosmos Wallet Support: Integrate with Keplr wallet for Cosmos-based transaction signing and broadcasting
  • Elder Ecosystem Integration: Seamlessly connect Rollapps to the Elder ecosystem with custom transaction handling
  • TypeScript Support: Fully typed codebase for better developer experience

Installation

Prerequisites

  • Node.js (v16 or higher recommended)
  • npm or yarn
  • A modern browser with Web3 support (for Ethereum) or Keplr wallet (for Cosmos)

Install via npm

npm install elderjs

Install from GitHub

Clone the repository and install dependencies:
git clone https://github.com/0xElder/elderjs.git
cd elderjs
npm install

Usage

Ethereum Wallet Example

import { eth_getElderMsgAndFeeTxRaw, eth_broadcastTx, eth_getElderAccountInfoFromSignature } from 'elderjs';
import { ethers } from "ethers";

function getWeb3Provider() {
    if (window.ethereum) {
        return new ethers.BrowserProvider(window.ethereum);
    }
    return null;
}
const provider = getWeb3Provider();

let message = "Sign to Login";
const signer = await provider.getSigner();
const signature = await signer.signMessage(message);
var { recoveredPublicKey, elderAddr } = await eth_getElderAccountInfoFromSignature(message, signature)

// Example transaction data
const tx = await DUMMY_CONTRACT.METHOD.populateTransaction();

const elderAddress = elderAddr;
const elderPublicKey = recoveredPublicKey;

const gasLimit = 21000;

const elderChainConfig = {
    chainName: "elder-testnet",
    rpc: "https://rpc.elder.example.com",
    rest: "https://rest.elder.example.com",
    rollChainID: 1234,
    
    // Elder Roll ID
    rollID: 2,
};

// Create and sign transaction
const { tx_hash, rawTx } = await eth_getElderMsgAndFeeTxRaw(
    tx,
    elderAddress,
    elderPublicKey,
    gasLimit,
    ethers.parseEther("1.0"),
    elderChainConfig
);

// Broadcast transaction
// broadcastResult.code == 0 (for tx success)
const broadcastResult = await eth_broadcastTx(rawTx, elderChainConfig.rpc);

console.log("Transaction Hash:", tx_hash);
console.log("Broadcast Result:", broadcastResult);

Cosmos Wallet Example (with Keplr)

import { cosmos_getElderClient, cosmos_getElderMsgAndFeeTxRaw, getEthereumAddressFromCosmosCompressedPubKey } from 'elderjs';

// Elder chain configuration
const elderChainConfig = {
    chainName: "elder-testnet",
    rpc: "https://rpc.elder.example.com",
    rest: "https://rest.elder.example.com",
    rollChainID: 1234,
    
    // Elder Roll ID
    rollID: 2,
};

// Connect to Keplr and get client
const { elderAddress, elderClient, elderPublicKey } = await cosmos_getElderClient(elderChainConfig);
const ethAddress = getEthereumAddressFromCosmosCompressedPubKey(elderPublicKey);
  
// Example transaction data
const tx = await DUMMY_CONTRACT.METHOD.populateTransaction();

// Create and sign transaction
const { tx_hash, rawTx } = await cosmos_getElderMsgAndFeeTxRaw(
    tx,
    elderAddress,
    elderPublicKey,
    21000, // gasLimit
    ethers.parseEther("1.0"),
    1234, // rollChainId
    2, // ElderRollID
    "elder-testnet"  // chainName
);

// Broadcast transaction using the client
// broadcastResult.code == 0 (for tx success)
const broadcastResult = await elderClient.broadcastTx(rawTx);

console.log("Transaction Hash:", tx_hash);
console.log("Broadcast Result:", broadcastResult);

Project Structure

elderjs/
├── eth_wallet/
│   └── index.js          # Ethereum wallet utilities
├── cosmos_wallet/
│   └── index.js          # Cosmos wallet utilities (Keplr integration)
├── common/               # Shared utilities and helpers
├── package.json          # Project metadata and dependencies
└── README.md            # This file

Dependencies

  • ethers: Ethereum JavaScript library for transaction handling
  • @cosmjs/stargate: Cosmos SDK client for transaction signing and broadcasting
  • @cosmjs/proto-signing: Protobuf-based signing utilities for Cosmos
  • bech32: Bech32 address encoding/decoding
  • @noble/hashes: Cryptographic hash functions
See package.json for the full list of dependencies.

Development

Transpile TypeScript

To transpile TypeScript files (if applicable):
npm run transpile-ts

Contributing

1

Fork the Repository

Fork the ElderJS repository to your GitHub account.
2

Create Feature Branch

Create a feature branch for your changes:
git checkout -b feature/your-feature
3

Make Changes

Implement your feature or fix and commit your changes:
git commit -m "Add your feature"
4

Push Changes

Push your branch to your fork:
git push origin feature/your-feature
5

Open Pull Request

Open a pull request on the main repository.

License

This project is licensed under the ISC License. See the LICENSE file for details.

Issues

Found a bug? Have a suggestion? Open an issue on the GitHub Issues page.

Contact

For questions or support, reach out via the GitHub repository.
For advanced configuration, troubleshooting, and updates, see the official ElderJS docs.