Documentation
๐Ÿงฉ gamba-react-v2

๐Ÿงฉ gamba-react-v2

NPMgamba-react-v2
๐Ÿงฉ

Gamba React package with essential hooks and context providers

npm install gamba-react-v2

๐Ÿ”„ Contexts

๐Ÿ”„

SendTransactionContext

  • Props:
    • priorityFee?: number
    • simulationUnits: number
    • computeUnitLimitMargin: number
import { SendTransactionProvider } from "gamba-react-v2";
 
// Wrap your app in SendTransactionProvider
function App() {
  return (
    <SendTransactionProvider
      priorityFee={10}
      simulationUnits={1000}
      computeUnitLimitMargin={200}
    >
      {/* Your application code */}
    </SendTransactionProvider>
  );
}
๐Ÿ”„

GambaContext

  • Props:
    • provider: GambaProvider
    • plugins: GambaPlugin[]
import { GambaProvider } from "gamba-react-v2";
 
// Wrap your app in GambaProvider
function App() {
  return (
    <GambaProvider provider={someProviderInstance} plugins={[plugin1, plugin2]}>
      {/* Your application code */}
    </GambaProvider>
  );
}
โš™๏ธ

SendTransactionProvider

  • Props:
    • children
    • Additional props from SendTransactionContext.
import { SendTransactionProvider } from "gamba-react-v2";
 
// Wrap your app or component in SendTransactionProvider
function App() {
  return (
    <SendTransactionProvider
      priorityFee={10}
      simulationUnits={1000}
      computeUnitLimitMargin={200}
    >
      {/* Your application code */}
    </SendTransactionProvider>
  );
}
โš™๏ธ

GambaProvider

  • Props:
    • __experimental_plugins?: GambaPlugin[]
    • children
import { GambaProvider } from 'gamba-react-v2;
 
// Wrap your app or component in GambaProvider
function App() {
  return (
    <GambaProvider provider={someProviderInstance} plugins={[plugin1, plugin2]}>
      {/* Your application code */}
    </GambaProvider>
  );
}

๐Ÿ“œ Types

๐Ÿ“œ

GambaEventType

  • Type: 'GameSettled' | 'PoolChange'
const eventType = "GameSettled";
๐Ÿ“œ

GambaTransaction

  • Props:
    • signature: string
    • time: number
    • name: GambaEventType
    • data: GambaEvent<Event>['data']
const gambaTransaction = {
  signature: "example-signature",
  time: Date.now(),
  name: "GameSettled",
  data: {
    /* event data */
  },
};
๐Ÿ“œ

GameResult

  • Props:
    • creator: PublicKey
    • user: PublicKey
    • rngSeed: string
    • payout: number
const gameResult = {
  creator: new PublicKey("example-creator"),
  user: new PublicKey("example-user"),
  rngSeed: "example-seed",
  payout: 1000,
};
๐Ÿ“œ

GambaPlayInput

  • Props:
    • wager: number
    • bet: number[]
    • creator: string | PublicKey
    • creatorFee?: number
    • jackpotFee?: number
    • clientSeed?: string
    • Other game input properties.
const playInput = {
  wager: 100,
  bet: [1, 2, 3],
  creator: new PublicKey("example-creator"),
};
๐Ÿ“œ

SendTransactionOptions

  • Props:
    • confirmation?: Commitment
    • lookupTable?: PublicKey[]
    • priorityFee?: number
    • computeUnitLimitMargin?: number
const options = {
  confirmation: "finalized",
  lookupTable: [new PublicKey("example-lookup")],
  priorityFee: 500,
};
๐Ÿ“œ

SendTransactionProps

  • Props:
    • Similar to SendTransactionOptions.
const sendTransactionProps = {
  ...options,
  simulationUnits: 50000,
};
๐Ÿ“œ

GambaProviderProps

  • Props:
    • __experimental_plugins?: GambaPlugin[]
const gambaProviderProps = {
  __experimental_plugins: [
    /* array of plugins */
  ],
};
๐Ÿ“œ

TransactionStore

  • Props:
    • state: 'none' | 'simulating' | 'processing' | 'signing' | 'sending' | 'confirming' | 'error'
    • label?: string
    • signatureResult?: any
    • txId: string | undefined
const transactionStore = {
  state: "none",
  label: "Sample Transaction",
  signatureResult: {},
  txId: "sample-tx-id",
};
๐Ÿ“œ

UseGambaEventsParams

  • Props:
    • address?: PublicKey
    • signatureLimit?: number
    • listen?: boolean
const gambaEventsParams = {
  address: new PublicKey("example-address"),
  signatureLimit: 10,
  listen: true,
};
๐Ÿ“œ

UiPoolState

  • Props:
    • publicKey: PublicKey
    • token: PublicKey
    • liquidity: bigint
const poolState = {
  publicKey: new PublicKey("pool-address"),
  token: new PublicKey("token-address"),
  liquidity: BigInt(500000),
};
๐Ÿ“œ

GambaPluginInput

  • Props:
    • wallet: PublicKey
    • creator: PublicKey
    • token: PublicKey
    • bet: number[]
    • wager: number
const pluginInput = {
  wallet: new PublicKey("wallet-address"),
  creator: new PublicKey("creator-address"),
  token: new PublicKey("token-address"),
  bet: [1, 2, 3],
  wager: 500,
};

๐Ÿ” Methods and Hooks

๐Ÿ”

useAccount

  • Props:
    • address: PublicKey
    • decoder: (x: AccountInfo<Buffer> | null) => T
const accountData = useAccount(new PublicKey("account-address"), decodeAccount);
๐Ÿ”

useWalletAddress

Returns the public key of the current wallet.

const walletAddress = useWalletAddress();
๐Ÿ”

useBalance

  • Props:
    • publicKey: PublicKey
    • token: PublicKey
const { balance, nativeBalance } = useBalance(
  new PublicKey("wallet-address"),
  new PublicKey("token-address")
);
๐Ÿ”

useTransactionError

  • Props:
    • callback: (error: Error) => void
useTransactionError((error) => {
  console.error("Transaction Error:", error);
});
๐Ÿ”

useSendTransaction

  • Props:
    • instructions: TransactionInstruction | Promise<TransactionInstruction>
const sendTransaction = useSendTransaction();
const txSignature = await sendTransaction([instruction]);
๐Ÿ”

useGambaPlay

  • Props:
    • input: GambaPlayInput
    • instructions?: TransactionInstruction[]
const playGame = useGambaPlay();
const gameResult = await playGame(playInput, [instruction]);
๐Ÿ”

useNextResult

Fetches the next game result.

const getNextResult = useNextResult();
const nextResult = await getNextResult();
๐Ÿ”

useGamba

Returns several functions, properties, and states.

const { play, result, userCreated } = useGamba();
const resultData = await result();
๐Ÿ”

useGambaEventListener

Adds an event listener for a specific Gamba event type.

useGambaEventListener("GameSettled", (event) => {
  console.log("Game Settled:", event);
});
๐Ÿ”

useGambaEvents

Fetches previous Gamba events.

const gambaEvents = useGambaEvents("GameSettled", {
  address: new PublicKey("event-address"),
});
๐Ÿ”

usePool

  • Props:
    • token: PublicKey
    • authority?: PublicKey
const poolData = usePool(
  new PublicKey("token-address"),
  new PublicKey("authority-address")
);
๐Ÿ”

useTransactionStore

Manages the transaction store states.

const transactionState = useTransactionStore();
๐Ÿ”

useGambaProvider

Returns the current Gamba provider.

const gambaProvider = useGambaProvider();
๐Ÿ”

useGambaProgram

Returns the Anchor program for the Gamba IDL.

const gambaProgram = useGambaProgram();
๐Ÿ”

useGambaContext

Provides access to the Gamba context.

const gambaContext = useGambaContext();

โš™๏ธ Utilities and Functions

โš™๏ธ

throwTransactionError

try {
  // Simulate or execute transaction
} catch (error) {
  throwTransactionError(error);
}
โš™๏ธ

createCustomFeePlugin

const feePlugin = createCustomFeePlugin("receiver-address", 5);