> For the complete documentation index, see [llms.txt](https://docs.lumia.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lumia.org/build-on-lumia/smart-contracts/interact-with-a-deployed-contract.md).

# Interact with a deployed contract

You already have a contract address on Lumia and want to call it, either from code or from the explorer UI.

**Who this is for:** developers with a contract already deployed on Lumia mainnet or Beam testnet (see [`/build/quickstart`](file:///5838283/Quickstart-your-first-contract-on-Lumia.md) or [`/build/smart-contracts/deploy-with-hardhat`](broken://pages/f176929e0032d6e7897dd25c5f662a1adae28160) if you don't have one yet). **Prerequisites:** a deployed contract address and its ABI; network values from [`/reference/networks`](file:///reference/Networks-and-endpoints.md). **Time:** 10-15 minutes.

## Steps

{% tabs %}
{% tab title="Option A: no code, via the block explorer" %}

1. Open the contract address on the relevant explorer: mainnet [`explorer.lumia.org`](https://explorer.lumia.org/) or Beam [`beam-explorer.lumia.org`](https://beam-explorer.lumia.org/) (see [`/reference/networks`](file:///reference/Networks-and-endpoints.md) for both).
2. If the contract is verified, the explorer's **Contract** tab exposes **Read Contract** and **Write Contract** sub-tabs generated from the ABI. Unverified contracts only expose raw calldata entry. Verify first with [`/build/smart-contracts/verify-with-hardhat`](broken://pages/1e93af03725a78c5c91c6a0808c099a17e27343d) or [`/build/smart-contracts/verify-with-truffle`](broken://pages/9ea94d5cc2e27d91093e485eab6c2189c9f3a45a) if you need the decoded UI.
3. **Read Contract**: expand a `view`/`pure` function, fill in arguments, click query. No wallet or gas needed.
4. **Write Contract**: connect a wallet (must be on the same network as the contract), expand the function, fill in arguments, submit. This costs gas in the native token.
   {% endtab %}

{% tab title="Option B: from a script, with ethers.js" %}

```bash
npm install ethers
```

{% code title="read.js" %}

```js
const { ethers } = require("ethers");

// Use the RPC value for the network your contract is on; see /reference/networks.
// Do not retype it from memory; the retired "Lumia Testnet" RPC (chain ID 1952959480) is dead.
const provider = new ethers.JsonRpcProvider("https://beam-rpc.lumia.org");

const abi = [ /* your contract's ABI */ ];
const address = "0xYourContractAddress";

async function main() {
  const contract = new ethers.Contract(address, abi, provider);
  const value = await contract.someViewFunction();
  console.log("Result:", value);
}

main();
```

{% endcode %}

To send a state-changing transaction, attach a signer instead of a bare provider:

{% code title="write.js" %}

```js
const { ethers } = require("ethers");

const provider = new ethers.JsonRpcProvider("https://beam-rpc.lumia.org");
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); // testnet key only
const abi = [ /* your contract's ABI */ ];
const contract = new ethers.Contract("0xYourContractAddress", abi, wallet);

async function main() {
  const tx = await contract.someStateChangingFunction(/* args */);
  const receipt = await tx.wait();
  console.log("Confirmed in block:", receipt.blockNumber);
}

main();
```

{% endcode %}

The web3.js equivalent (`new Web3(rpcUrl)`, `new web3.eth.Contract(abi, address)`) follows the same shape: provider/RPC URL, ABI, address, then `.methods.fn().call()` for reads or `.send({ from })` for writes.
{% endtab %}
{% endtabs %}

## Verify it worked

* A read call returns a decoded value with no error.
* A write call's `tx.wait()` (or the explorer's pending-tx banner) resolves to a receipt; open the transaction hash on the explorer and confirm status is **Success**.

## Troubleshooting

<details>

<summary><code>call revert exception</code> on a read</summary>

Check you're calling the right function signature/ABI and that any required state (e.g. an allowlist) is satisfied; an unverified contract with a hand-written ABI is the most common cause of a mismatch.

</details>

<details>

<summary>Wallet shows the wrong chain / transaction never confirms</summary>

Your wallet is pointed at a different network. Re-check against [`/reference/networks`](file:///reference/Networks-and-endpoints.md); this is exactly the trap the retired chain ID `1952959480` sets for anyone following an old tutorial.

</details>

<details>

<summary><code>insufficient funds for gas</code></summary>

Fund the account from [`/reference/faucet`](file:///reference/Testnet-faucet.md) (Beam) or your own mainnet balance.

</details>
