EVER SDK
Developer ToolsEver PlatformForum
  • Ever SDK
  • Quick start (JavaScript)
  • Add EVER to your backend
  • Reference
    • Types and Methods
      • Modules
      • Module abi
      • Module boc
      • Module client
      • Module crypto
      • Module debot
      • Module net
      • Module processing
      • Module proofs
      • Module tvm
      • Module utils
    • Error API
    • Error Codes
    • JavaScript Reference
    • Rust Reference
  • Samples
    • JavaScript Samples
  • guides
    • Installation
      • Add SDK to your App
    • Configuration
      • Endpoint Configuration
      • Message Expiration
      • Message Retry
      • Config Reference
    • Work with contracts
      • Add Contract to your App
      • Use your own Giver
      • Deploy
      • Run on-chain
      • Run ABI Get Method
      • Run Fift Get Method
      • Query/Subscribe for messages(events)
      • Decode Messages(Event)
      • External Signing
      • Emulate Transaction
      • Estimate Fees
      • Validate address, convert address
      • Monitor Messages
      • Trace message processing with REMP
    • Crypto
      • Mnemonics and Keys
    • Queries and subscriptions
      • Use-cases
      • How to work with net module
      • net.query syntax
      • Data pagination
      • Subscribe to Updates
      • Query Collection
      • Aggregate Collection
  • For Binding Developers
    • How to work with Application Objects in binding generators
    • JSON Interface to Ton Client
  • Links
    • Ever SDK repository
    • AppKit JS documentation
Powered by GitBook
On this page
  • Run get method
  • Source code

Was this helpful?

  1. guides
  2. Work with contracts

Run ABI Get Method

PreviousRun on-chainNextRun Fift Get Method

Last updated 1 year ago

Was this helpful?

Run ABI compatible get methods

Run get method

With low level SDK get method is executed in 3 steps:

  1. Download the latest Account State (BOC)

  2. Encode message that calls the method

  3. Execute the message locally on the downloaded state:

Here is the sample that executes the get method getTimestamp on the latest account's state.

  1. account boc is downloaded with blockchain API

  2. message that calls contract's function getTimestamp is encoded with encode_message function

  3. message is executed on local TVM with run_tvm method

 async function getAccount(address) {

    // `boc` or bag of cells - native blockchain data layout. Account's boc contains full account state (code and data) that
    // we will  need to execute get methods.
    const query = `
        query {
          blockchain {
            account(
              address: "${address}"
            ) {
               info {
                balance(format: DEC)
                boc
              }
            }
          }
        }`
    const {result}  = await client.net.query({query})
    const info = result.data.blockchain.account.info
    return info
}
async function runGetMethod(methodName, address, accountState) {
    // Execute the get method `getTimestamp` on the latest account's state
    // This can be managed in 3 steps:
    // 1. Download the latest Account State (BOC) 
    // 2. Encode message
    // 3. Execute the message locally on the downloaded state

    // Encode the message with `getTimestamp` call
    const { message } = await client.abi.encode_message({
        // Define contract ABI in the Application
        // See more info about ABI type here:
        // https://github.com/everx-labs/ever-sdk/blob/master/docs/reference/types-and-methods/mod_abi.md#abi
        abi: {
            type: 'Contract',
            value: HelloWallet.abi,
        },
        address,
        call_set: {
            function_name: methodName,
            input: {},
        },
        signer: { type: 'None' },
    });

    // Execute `getTimestamp` get method  (execute the message locally on TVM)
    // See more info about run_tvm method here:
    // https://github.com/everx-labs/ever-sdk/blob/master/docs/reference/types-and-methods/mod_tvm.md#run_tvm
    console.log('Run `getTimestamp` get method');
    const response = await client.tvm.run_tvm({
        message,
        account: accountState,
        abi: {
            type: 'Contract',
            value: HelloWallet.abi,
        },
    });
    return response.decoded.output
}

Source code

Check out for this use case.

https://github.com/everx-labs/sdk-samples/blob/master/core-examples/node-js/hello-wallet/index.js
AppKit documentation
Run get method
Source code