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.
-
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.
-
Node.js (v16 or higher recommended)
-
npm or yarn
-
A modern browser with Web3 support (for Ethereum) or Keplr wallet (for Cosmos)
npm install elderjs
Clone the repository and install dependencies:
git clone https://github.com/0xElder/elderjs.git
cd elderjs
npm installimport { 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);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);
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
-
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.
To transpile TypeScript files (if applicable):
npm run transpile-ts
Contributions are welcome! Please follow these steps:
-
Fork the repository.
-
Create a feature branch (
git checkout -b feature/your-feature). -
Commit your changes (
git commit -m "Add your feature"). -
Push to the branch (
git push origin feature/your-feature). -
Open a pull request.
This project is licensed under the ISC License. See the LICENSE file for details.
Found a bug? Have a suggestion? Open an issue on the GitHub Issues page.
For questions or support, reach out via the GitHub repository.
Happy coding with ElderJS! 🚀