Asentum

Use the Network

Interact with a Contract

Estimated read time: 8 minutes

Reading vs writing

Contracts on Asentum expose two kinds of operations:

  • Read calls ask the contract a question and don't change any state. They're free — no signature, no gas, no transaction. The result comes back immediately.
  • Write calls mutate state and have to be signed and broadcast as a transaction. They cost gas and take a couple of blocks to finalize.

From a browser dApp

Most dApps will surface contract interactions via a UI. The user clicks a button, the dApp shows what's about to happen, and the wallet pops up a signing prompt.

Before you sign anything, the wallet will tell you whether the contract you're interacting with is:

  • Immutable — the code can never change. What you audited (or what your wallet's risk-score service audited) is what will run.
  • Upgradeable — the code can be replaced by an upgrade authority. The wallet will show you who that authority is. Always check.

This is unique to Asentum. On most other chains you have to dig for this information yourself. On Asentum it's surfaced before every signing prompt.

From the SDK

import { Chain, Wallet } from '@asentum/sdk';

const chain = new Chain({ rpc: 'https://rpc-testnet.asentum.io' });
const wallet = await Wallet.fromKeystore('./my-key.json');

// Get a contract instance
const token = await chain.contract('0x5aC14fD3A2c0e8ee48B07C8A3D1Ebf27b0EeDF0C');

// Read call (free)
const balance = await token.balanceOf(wallet.address);
console.log('Balance:', balance);

// Write call (signed transaction)
const tx = await token.transfer(
  '0xabc...',
  100n * 10n ** 18n,
  { signer: wallet }
);
await tx.wait();
console.log('Transferred. Tx hash:', tx.hash);

Atomic transaction bundles

When you need multiple contract calls to succeed or fail as a single unit, use a transaction bundle. This is Asentum's first-class replacement for the "Flashbots bundle" pattern, and it's safer than chaining synchronous contract calls.

const bundle = await chain.bundle([
  { to: lendingMarket, method: 'borrow', args: [usdc, 10_000n] },
  { to: dex,           method: 'swap',   args: [usdc, eth, 10_000n] },
  { to: lendingMarket, method: 'repay',  args: [eth] },
], { signer: wallet });

// All three calls execute atomically. If any one fails, the entire
// bundle reverts and no state changes are committed.
await bundle.wait();

Safety: what to check first

Asentum makes a number of trust questions much easier to answer than other chains. Before interacting with an unfamiliar contract:

  1. Read the source. Every contract is plain JavaScript on-chain. The block explorer shows it directly. Read it.
  2. Check the immutability badge. If the contract is upgradeable, verify the upgrade authority is who you expect.
  3. Check the deploy history. When was it deployed? By whom? How much activity has it seen?
  4. Hash-verify the source. Hash the source you see locally and confirm it matches the deployed code hash. Or trust your wallet to do this for you.

Reentrancy is structurally impossible on Asentum, so you don't have to worry about that class of attack. But contracts can still have ordinary bugs, ordinary economic exploits, and ordinary scams. Read the code, especially before you authorize a token spend.

Read next