Skip to main content

Contracts Overview

The ONE SDK exposes contract interaction through the Engine API layer. There are no dedicated React hooks or components for contracts -- you use useOneEngine() to obtain the OneEngineClient instance and call its contract methods directly.

Quick Start

import { useOneEngine } from '@one_deploy/sdk';

function ContractPage() {
const { client } = useOneEngine();

async function fetchContracts() {
const res = await client.getUserContracts();
console.log(res.data); // Contract[]
}

return <button onClick={fetchContracts}>Load My Contracts</button>;
}

In a non-React environment (Node, Edge, scripts), create the client directly:

import { OneEngineClient } from '@one_deploy/sdk';

const client = new OneEngineClient({
apiKey: process.env.ONE_API_KEY!,
projectId: process.env.ONE_PROJECT_ID!,
});

const res = await client.getUserContracts();

Available Methods

MethodDescription
getUserContracts(options?)List all contracts the current user has deployed or interacted with.
getContractDetails(address, chainId)Fetch metadata, ABI, and on-chain state for a single contract.
readContract(params)Call a read-only (view / pure) function on any contract.
writeContract(params)Send a state-changing transaction to a contract.
deployContract(params)Deploy a new contract from a supported template or custom bytecode.
createWebhook(params)Subscribe to contract events via webhooks.
getTransactionStatus(txHash, chainId)Poll transaction confirmation status.

Core Types

Contract

import type { Contract, ContractType } from '@one_deploy/sdk';

interface Contract {
address: string;
chainId: number;
name: string;
type: ContractType;
abi?: Record<string, unknown>[];
deployedAt?: string; // ISO-8601 timestamp
deployerAddress?: string;
metadata?: Record<string, unknown>;
}

ContractType

type ContractType =
| 'erc20'
| 'erc721'
| 'erc1155'
| 'custom'
| 'marketplace'
| 'staking'
| 'governance';

getUserContracts

Retrieve all contracts associated with the authenticated user.

interface GetUserContractsOptions {
chainId?: number; // Filter by chain
type?: ContractType; // Filter by contract type
page?: number; // Pagination (1-based)
limit?: number; // Items per page (default 20, max 100)
}

const res = await client.getUserContracts({
chainId: 137,
type: 'erc20',
limit: 50,
});

// res.data -> Contract[]
// res.meta -> { page: number; limit: number; total: number }

getContractDetails

Fetch full details for a specific contract, including the ABI when available.

const res = await client.getContractDetails(
'0x1234...abcd', // contract address
137, // chainId (Polygon)
);

const contract: Contract = res.data;
console.log(contract.name); // "MyToken"
console.log(contract.type); // "erc20"
console.log(contract.abi); // [...] full ABI array

API-Only -- No React Components

Unlike the Wallet and Payments sections, the Contracts module does not ship pre-built React components. All operations are performed through OneEngineClient methods. If you need a React-friendly wrapper, use useOneEngine() inside your own components:

import { useOneEngine } from '@one_deploy/sdk';
import { useEffect, useState } from 'react';
import type { Contract } from '@one_deploy/sdk';

function ContractList() {
const { client } = useOneEngine();
const [contracts, setContracts] = useState<Contract[]>([]);

useEffect(() => {
client.getUserContracts().then((res) => setContracts(res.data));
}, [client]);

return (
<ul>
{contracts.map((c) => (
<li key={c.address}>
{c.name} ({c.type}) -- {c.address.slice(0, 10)}...
</li>
))}
</ul>
);
}
tip

For full method signatures and response shapes, see the Contracts & NFTs API Reference.

Next Steps