> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pumpevm.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# Smart contract integration

> Read and write to launchpad bonding curve contracts with viem.

All examples use [viem](https://viem.sh). Replace `tokenAddress` with the bonding curve address of the token you are integrating with.

## Get token information

```ts theme={null}
import { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';

const client = createPublicClient({
  chain: mainnet,
  transport: http(),
});

const tokenDetails = await client.readContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'getBondingCurveSettings',
});
```

## Get current price

```ts theme={null}
const price = await client.readContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'getPriceForBuy',
  args: [parseEther('0.1')],
});
```

## Buy tokens

```ts theme={null}
import { createWalletClient, custom } from 'viem';

const walletClient = createWalletClient({
  transport: custom(window.ethereum),
});

const hash = await walletClient.writeContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'buy',
  value: parseEther('1'),
});
```

## Sell tokens

```ts theme={null}
const hash = await walletClient.writeContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'sell',
  args: [parseEther('1000')],
});
```

## Check phase

```ts theme={null}
const currentPhase = await client.readContract({
  address: tokenAddress,
  abi: bondingCurveAbi,
  functionName: 'currentPhase',
});
// 0 = Pre-Bond, 1 = Bonding, 2 = Finalized
```
