---
title: "Example Usage"
description: "Learn how to interact with Paxeer precompiles using ethers.js to query and execute CosmWasm contracts from the EVM."
keywords: ["precompile example", "ethers.js", "cosmwasm query", "evm integration", "paxeer precompiles", "smart contract interaction", "wasm precompile"]
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.


<Info>
Per [Proposal 115](https://.app/proposals/115), no new CosmWasm contracts can be deployed on Paxeer. The examples below apply to **pre-existing CosmWasm contracts** only - `instantiate()` will revert. Separately, [Proposal 116](https://.app/proposals/116) disables inbound IBC transfers as part of the [SIP-03](/learn) migration.
</Info>

The Paxeer precompiles can be used like any standard smart contract on the EVM. For
example, using [ethers.js](https://docs.ethers.org/v6/), you can query and
execute actions on an existing CosmWasm contract as follows:

## Setup

To install `ethers`, run the following command in your project directory
terminal:

```bash
npm install ethers
npm install @sei-js/evm
```

Next, you'll need to use one of the precompiles in `EVM Precompiles` section. In
this example, we're going to be using the [wasmd precompile](/evm/precompiles/cosmwasm-precompiles/cosmwasm):

```typescript
// Import Wasm precompile address and ABI
// View the entire ABI here: https://github.com/paxeer-network/paxeer-chain/tree/evm/precompiles/wasmd
import { WASM_PRECOMPILE_ABI, WASM_PRECOMPILE_ADDRESS } from '@sei-js/evm';
```

## Using the contract

Next, we'll set up a provider and contract to interact with the blockchain:

```typescript
import { ethers, toUtf8Bytes, toUtf8String } from 'ethers';

// Using MetaMask as the signer and provider
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

// Create a contract with the signer
const contract = new ethers.Contract(WASM_PRECOMPILE_ADDRESS, WASM_PRECOMPILE_ABI, signer);
```

### Querying & Executing a CosmWasm Contract

Once you have the contract, you can query and execute messages to any CosmWasm
smart contract. In the below example we assume there is a counter contract with a `get_count` function

```typescript
// Replace with your contract
const COUNTER_CONTRACT_ADDRESS = 'pax1eyf...xff';

// Query to get the count on the counter contract (replace with function from your ABI)
const queryMsg = { get_count: {} };
const queryResponse = await contract.query(COUNTER_CONTRACT_ADDRESS, toUtf8Bytes(JSON.stringify(queryMsg)));
console.log(toUtf8String(queryResponse));

// Execute message to increment the count on the contract. (Replace with any function from your ABI)
// No funds are attached since the increment method does not require HPX. (Your ABI may require funds)
const executeMsg = { increment: {} };
const executeResponse = await contract.execute(
  COUNTER_CONTRACT_ADDRESS,
  toUtf8Bytes(JSON.stringify(executeMsg)),
  toUtf8Bytes(JSON.stringify([])) // Used for sending funds if needed
);

// Wait for the transaction to be confirmed
await executeResponse.wait();
console.log(executeResponse);
```

### Executing a payable function

In this example, we execute the 'donate' method on our contract. This is similar
to the `increment` method, but also receives funds from the user and stores it
in the contract.

```typescript
// Execute a message to donate to the contract.
const executeMsg = { donate: {} };

// Funds are attached via overrides. This example is specific to ethers.js
const overrides = {
  value: ethers.parseEther('3.2') // Sending 3.2 HPX
};
const executeResponse = await contract.execute(
  COUNTER_CONTRACT_ADDRESS,
  toUtf8Bytes(JSON.stringify(executeMsg)),
  toUtf8Bytes(JSON.stringify([{ denom: 'uusdc', amount: '100' }])), // Also send 100 uusdc
  overrides
);

await executeResponse.wait();
const receipt = await provider.getTransactionReceipt(executeResponse.hash);
```

For payable contracts, Paxeer amounts have to be sent directly to the contract
while other denoms should use the `coins` field.
