Signing - Ethereum

BitBadges Chain supports Ethereum-compatible transactions through EVM precompiles. The SDK automatically converts Cosmos SDK messages to EVM precompile function calls when an EVM address is provided in the transaction context.

Overview

When using Ethereum wallets (MetaMask, Privy, etc.), transactions are signed as EVM transactions and sent to precompile contracts. The SDK handles the conversion from Cosmos SDK messages to EVM precompile calls automatically.

Transaction Payload with EVM Support

The createTransactionPayload function now supports optional EVM precompile conversion. When you provide an evmAddress in the TxContext, the SDK will:

  1. Create the standard Cosmos transaction payload (for compatibility)

  2. Convert messages to EVM precompile calls (if supported)

  3. Return both in the TransactionPayload with an optional evmTx field

Basic Usage

import { createTransactionPayload, TxContext, MsgTransferTokens } from 'bitbadgesjs-sdk';

// Create your messages
const msg = new MsgTransferTokens({
  creator: 'bb1...', // BitBadges address
  collectionId: '1',
  transfers: [/* ... */]
});

// Create transaction context with evmAddress
const txContext: TxContext = {
  testnet: false,
  sender: {
    address: 'bb1...', // BitBadges address (bb-prefixed)
    sequence: 0,
    accountNumber: 1,
    publicKey: '', // Not needed for EVM transactions
  },
  fee: {
    amount: '0',
    denom: 'ubadge',
    gas: '200000',
  },
  memo: '',
  evmAddress: '0x1234...', // βœ… Add EVM address to enable precompile conversion
};

// Create payload - SDK will automatically convert to EVM format
const payload = createTransactionPayload(txContext, msg);

// Check if EVM transaction is available
if (payload.evmTx) {
  // Use EVM transaction details
  const { to, data, value, functionName } = payload.evmTx;
  // to: precompile address (0x1001, 0x1002, or 0x1003)
  // data: encoded function call data
  // value: always "0" for precompiles
  // functionName: function name for debugging
}

Signing EVM Transactions

Using ethers.js

Precompile Addresses

The SDK automatically selects the correct precompile address based on message type:

Precompile
Address
Message Types

Tokenization

0x0000000000000000000000000000000000001001

All tokenization module messages

Gamm

0x0000000000000000000000000000000000001002

Pool operations (JoinPool, ExitPool, SwapExactAmountIn, etc.)

SendManager

0x0000000000000000000000000000000000001003

MsgSend (native coin transfers)

Supported Message Types

Tokenization Messages

All tokenization module messages are supported:

  • MsgTransferTokens

  • MsgCreateCollection

  • MsgUniversalUpdateCollection

  • MsgSetIncomingApproval

  • MsgSetOutgoingApproval

  • MsgSetCollectionApprovals

  • MsgSetTokenMetadata

  • MsgSetCollectionMetadata

  • MsgCreateDynamicStore

  • MsgUpdateDynamicStore

  • MsgDeleteDynamicStore

  • MsgSetDynamicStoreValue

  • And all other tokenization messages

Gamm Messages

  • MsgCreateBalancerPool

  • MsgJoinPool

  • MsgExitPool

  • MsgSwapExactAmountIn

  • MsgSwapExactAmountInWithIBCTransfer

Bank Messages

  • MsgSend (via SendManager precompile)

Multiple Messages

For multiple tokenization messages, the SDK uses the executeMultiple precompile function:

Note: Multiple messages must all be tokenization messages. Mixed message types (e.g., tokenization + gamm) are not supported in a single transaction.

Transaction Context for EVM

When creating a transaction context for EVM transactions:

Important Notes:

  • sender.address must be a BitBadges address (bb-prefixed)

  • evmAddress should be the Ethereum address (0x-prefixed) of the same account

  • publicKey is not required for EVM transactions (can be empty string)

  • The SDK handles address conversion between formats automatically

Error Handling

If a message type is not supported for EVM conversion, payload.evmTx will be undefined. You should check for this:

Complete Example

Differences from Cosmos Signing

Aspect
Cosmos
Ethereum

Wallet

Keplr, Leap, etc.

MetaMask, Privy, etc.

Address Format

bb1... (Bech32)

0x... (Hex)

Public Key

Required

Not required

Signature Format

Cosmos Direct/Amino

EVM (EIP-155)

Message Format

Protobuf

Precompile JSON string

Transaction Type

Cosmos SDK messages

EVM contract calls

See Also

Last updated