home / skills / multiversx / mx-ai-skills / mvx_sdk_js_contracts

mvx_sdk_js_contracts skill

/antigravity/skills/mvx_sdk_js_contracts

This skill helps you manage MultiversX JS smart contracts by loading ABIs, deploying, calling, querying, and parsing results safely.

npx playbooks add skill multiversx/mx-ai-skills --skill mvx_sdk_js_contracts

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.4 KB
---
name: mvx_sdk_js_contracts
description: Smart contract operations for MultiversX TypeScript/JavaScript SDK.
---

# MultiversX SDK-JS Smart Contract Operations

This skill covers ABI loading, deployments, calls, queries, and parsing.

## ABI Loading

```typescript
import { Abi } from "@multiversx/sdk-core";
import { promises } from "fs";

// From file
const abiJson = await promises.readFile("contract.abi.json", "utf8");
const abi = Abi.create(JSON.parse(abiJson));

// From URL
const response = await axios.get("https://example.com/contract.abi.json");
const abi = Abi.create(response.data);

// Manual construction
const abi = Abi.create({
    endpoints: [{
        name: "add",
        inputs: [{ type: "BigUint" }],
        outputs: [{ type: "BigUint" }]
    }]
});
```

## Smart Contract Controller

```typescript
const controller = entrypoint.createSmartContractController(abi);
```

## Deployment

```typescript
const bytecode = await promises.readFile("contract.wasm");

const tx = await controller.createTransactionForDeploy(account, nonce, {
    bytecode: bytecode,
    gasLimit: 60_000_000n,
    arguments: [42]  // Constructor args (plain values with ABI)
});

const txHash = await entrypoint.sendTransaction(tx);
const outcome = await controller.awaitCompletedDeploy(txHash);
const contractAddress = outcome[0].contractAddress;
```

## Contract Calls

```typescript
// With ABI - use plain values
const tx = await controller.createTransactionForExecute(account, nonce, {
    contract: contractAddress,
    function: "add",
    arguments: [42],
    gasLimit: 5_000_000n
});

// Without ABI - use TypedValue
import { U32Value, BigUintValue } from "@multiversx/sdk-core";
const tx = await controller.createTransactionForExecute(account, nonce, {
    contract: contractAddress,
    function: "add",
    arguments: [new U32Value(42)],
    gasLimit: 5_000_000n
});
```

## Transfer & Execute (Send tokens to SC)

```typescript
const tx = await controller.createTransactionForExecute(account, nonce, {
    contract: contractAddress,
    function: "deposit",
    arguments: [],
    gasLimit: 10_000_000n,
    nativeTransferAmount: 1_000_000_000_000_000_000n,  // 1 EGLD
    tokenTransfers: [
        TokenTransfer.fungibleFromBigInteger("TOKEN-abc123", 1000n)
    ]
});
```

## VM Queries (Read-Only)

```typescript
const controller = entrypoint.createSmartContractController(abi);

const result = await controller.queryContract({
    contract: contractAddress,
    function: "getSum",
    arguments: []
});

// Parsed output (with ABI)
const sum = result[0];  // Automatically typed
```

## Upgrades

```typescript
const newBytecode = await promises.readFile("contract_v2.wasm");

const tx = await controller.createTransactionForUpgrade(account, nonce, {
    contract: contractAddress,
    bytecode: newBytecode,
    gasLimit: 60_000_000n,
    arguments: []
});
```

## RelayedV3 Contract Calls

```typescript
const tx = await controller.createTransactionForExecute(account, nonce, {
    contract: contractAddress,
    function: "endpoint",
    arguments: [],
    gasLimit: 5_050_000n,  // +50,000 for relayed
    relayer: relayerAddress
});

tx.relayerSignature = await relayer.signTransaction(tx);
```

## Best Practices

1. **Always use ABI** when available for type safety
2. **Gas estimation**: Start high, optimize later
3. **Simulate first**: Use `simulateTransaction()` before real calls
4. **Parse outcomes**: Use `awaitCompletedExecute()` for return values

Overview

This skill implements smart contract operations for the MultiversX TypeScript/JavaScript SDK. It provides ABI loading, deployment, execute calls, read-only VM queries, upgrades, relayed calls, and utilities for transfers and token operations. The goal is to make contract interactions type-safe, predictable, and easy to integrate into JS/TS apps.

How this skill works

Load an ABI from file, URL, or construct it manually to enable typed inputs and outputs. Create a Smart Contract Controller from the ABI to generate transactions for deploy, execute, upgrade, and queries. The controller can build transactions using plain values (when ABI available) or TypedValue objects, send them through an entrypoint, and await parsed outcomes with helper methods.

When to use it

  • Deploying new smart contracts or upgrading existing WASM bytecode
  • Executing state-changing contract endpoints, including token transfers and native EGLD transfers
  • Running read-only VM queries to fetch on-chain data without gas costs
  • Building relayed transactions that require a relayer signature
  • Simulating transactions before sending to reduce failed executions

Best practices

  • Always use the ABI when available to get automatic type parsing and safer argument handling
  • Estimate gas conservatively at first (start high), then optimize after profiling
  • Simulate transactions using simulateTransaction() to catch errors before consuming gas
  • Use awaitCompletedExecute()/awaitCompletedDeploy() to parse return values and verify outcomes
  • Include a small extra gas buffer for relayed calls (+50,000 gas typical)

Example use cases

  • Load a contract ABI from a URL, create a controller, and query a getter to display on a dashboard
  • Deploy a new contract with constructor args, wait for completion, and record the deployed address
  • Execute a deposit endpoint that sends 1 EGLD and a fungible token transfer in a single transaction
  • Upgrade an existing contract by sending new WASM bytecode with proper constructor args
  • Create a relayed transaction, attach relayerSignature, and submit it via the relayer infrastructure

FAQ

Do I need an ABI to interact with a contract?

No — you can use TypedValue objects to call endpoints without an ABI, but using an ABI provides automatic type conversion and parsed outputs.

How do I get return values from a contract call?

Use awaitCompletedExecute() or queryContract(); when an ABI is present returned values are automatically parsed into typed JS/TS values.