Trading API
Sign with your wallet
What a quote's message and transaction are, how your signature becomes a GUM Network typed signature, and how to sign with a Solana or EVM key in JavaScript, Python, Rust or Go, or with a browser wallet.
Every quote returns two base64 strings:
transaction: the whole GUM Network transaction, in its wire format. Send it back unchanged.message: the part oftransactionthat signatures cover. Sign these bytes with your wallet.
The quote’s signer.address is the GUM account that must sign, and
signer.signWith says how: solana or evm. In the examples, message is
the decoded bytes.
What’s in the transaction
A GUM Network transaction is a Solana legacy message with typed signature records in front, one per signer. Each record is a length, a one-byte type tag and the signature, and record i signs for account i of the message. GUM’s fee payer comes first and has already signed, so every quote starts like this:
offset bytes meaning
0 02 2 records: GUM's fee payer, then you
1 41 00 length 65, tag 0x00 (Ed25519)
3–66 64 bytes the fee payer's signature
67 41 00 length 65, tag 0x00
69–132 64 zeros your slot, empty until you sign
133– … the Solana legacy message: messageYou never build a record, and a Solana SDK can’t: it writes bare 64-byte
signatures, without the length and tag. Sign message the way your wallet
signs anything and send only the signature. The API turns it into your typed
signature, checks it against message exactly as GUM Network validators will,
writes it into your slot and submits the transaction:
signWith | You send | Your record becomes |
|---|---|---|
solana | The 64-byte Ed25519 signature | 41 (length 65), 00, then the signature: 66 bytes |
evm | The 65-byte personal_sign signature: r, s, v | 82 01 (length 130), 10, then your 65-byte public key, r and s: 132 bytes |
For an EVM wallet, the API recovers your public key from the signature and
drops v, because a typed signature carries the key instead. It also switches
a high s to the low form GUM Network requires.
Your account is the address your record signs for. For a Solana wallet, that’s
its public key. For an EVM wallet, it’s a
typed address built from your 0x
address and tag 0x10. Pass either form as address.
Solana keys
Sign the raw message bytes with Ed25519. Send the 64-byte signature as
base58, base64 or hex.
import bs58 from "bs58";
import nacl from "tweetnacl";
const signature = bs58.encode(nacl.sign.detached(message, secretKey));from solders.keypair import Keypair
keypair = Keypair.from_base58_string(secret_key)
signature = str(keypair.sign_message(message))use ed25519_dalek::{Signer, SigningKey};
let keypair: [u8; 64] = bs58::decode(secret_key).into_vec()?.try_into().unwrap();
let signing_key = SigningKey::from_keypair_bytes(&keypair)?;
let signature = bs58::encode(signing_key.sign(&message).to_bytes()).into_string();import (
"crypto/ed25519"
"github.com/mr-tron/base58"
)
key, err := base58.Decode(secretKey)
if err != nil {
return err
}
signature := base58.Encode(ed25519.Sign(ed25519.PrivateKey(key), message))Solana browser wallets
Wallets don’t sign arbitrary bytes that look like a transaction, so wrap
message in one and ask the wallet to sign it. The signature covers the same
bytes. This is how the GUM app signs. Send only your signature: the
transaction the wallet returns is in Solana’s format, which GUM Network can’t
read.
import { VersionedMessage, VersionedTransaction } from "@solana/web3.js";
import bs58 from "bs58";
const solanaMessage = VersionedMessage.deserialize(message);
const signed = await wallet.signTransaction(
new VersionedTransaction(solanaMessage)
);
const index = solanaMessage.staticAccountKeys.findIndex((key) =>
key.equals(wallet.publicKey)
);
const signature = bs58.encode(signed.signatures[index]);Perps order and cancel quotes
Perps margin deposits, withdrawals and leverage updates return a GUM Network
transaction message (sign them with signTransaction above). Perps order
(/v1/perps/orders/quote) and cancel (/v1/perps/orders/cancel/quote)
quotes instead return serialized GUM Perps action bytes, not a Solana
transaction message. Decode message from base64 and sign those bytes directly
with wallet.signMessage:
import bs58 from "bs58";
const bytes = Uint8Array.from(atob(quote.message), (c) => c.charCodeAt(0));
const signatureBytes = await wallet.signMessage(bytes);
const signature = bs58.encode(signatureBytes);Raw Solana keys (Ed25519 over the decoded message bytes) and EVM wallets
(personal_sign) sign both transaction messages and Perps action bytes the
same way.
EVM keys and wallets
Sign the raw message bytes with personal_sign (EIP-191). Send the 65-byte
signature as hex.
const signature = await account.signMessage({ message: { raw: message } });const signature = await wallet.signMessage(message);const hex = Array.from(message, (byte) => byte.toString(16).padStart(2, "0"));
const signature = await window.ethereum.request({
method: "personal_sign",
params: [`0x${hex.join("")}`, address],
});from eth_account import Account
from eth_account.messages import encode_defunct
signed = Account.sign_message(encode_defunct(primitive=message), private_key=key)
signature = signed.signature.hex()use alloy::signers::{local::PrivateKeySigner, Signer};
let signer: PrivateKeySigner = private_key.parse()?;
let signature = signer.sign_message(&message).await?;
let signature = alloy::hex::encode_prefixed(signature.as_bytes());import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
sig, err := crypto.Sign(accounts.TextHash(message), privateKey)
if err != nil {
return err
}
signature := hexutil.Encode(sig)