blueprint icon indicating copy to clipboard operation
blueprint copied to clipboard

Missing `getContractState` method in `TonClient` TypeScript definitions

Open UltronOne opened this issue 1 year ago • 4 comments

Description I encountered a TypeScript error when trying to use the getContractState method on the TonClient. The method seems not to exist on the type TonClient4 | TonClient, which leads to a compilation error. I am following the official documentation (or specific guide/tutorial - if applicable, provide the link) to deploy a smart contract on the TON blockchain.

Library Version

  • TON SDK version: "@ton/blueprint": "^0.19.0",

Steps to Reproduce run this line const contractState = await api.getContractState(minterAddress);

Expected Behavior The getContractState method should be available and callable on the TonClient instance to fetch the current state of a smart contract.

Actual Behavior TypeScript compilation error stating that getContractState does not exist on the TonClient4 | TonClient.

Could someone please clarify if this method has been removed, deprecated, or replaced in the latest version of the SDK? Any guidance on how to properly obtain a contract's state using the current SDK version would also be appreciated.

Thank you!

UltronOne avatar May 09 '24 12:05 UltronOne

the same issue

dev1line avatar Jun 15 '24 11:06 dev1line

A simpe workaround is to use getContractState method of TonClient, similarly to this:

import { TonClient } from '@ton/ton'
import { getHttpEndpoint } from '@orbs-network/ton-access'

const clientPromise = getHttpEndpoint({ network: "mainnet" })
    .then((endpoint) => new TonClient({ endpoint }))

const getContractState = async (address: Address) => {
    const client = await clientPromise
    return client.getContractState(address)
}

YakovL avatar Jul 14 '24 15:07 YakovL

I'm also now encountering this problem.

The definition exists on TonClient but not on TonClient 4.

When returning a shape of TonClient | TonClient 4 Typescript will only be happy when a function declared on both are being used.

Creating a TonClient or narrowing the scope of TonClient | TonClient 4 with validation, might be way to go, for now.

CjHare avatar Sep 03 '24 05:09 CjHare

Any progress or workaround for this problem? How would I know what client is returned from api()?

rafalbednarczuk avatar Oct 02 '24 11:10 rafalbednarczuk