0

I'm trying to access data inside a smart contract. The contract is visible here for example.

The documentation for the smart contract is accessible here

An example of an instance of the contract (one of the converter in my specific example) can be found here.

My goal is to access the data that are contained inside that instance (bnt2eoscnvrt in my case) and more specifically I would like to access the field uint64_t ratio; which is in the public definition of the Main Smart Contract.

I'm mostly using NodeJs and the EOSIO JS driver but any example would do it... I'm quite lost to be honest, I'm sure that's not so complex but I'm failing to understand the logic and when one spends too much time on an issue, one loose track of propre judgment I guess ;-)

Many thanks in advance for any assistance

1

You need to fetch the table where the data is stored and then access the field.

First, you need to setup eosjs:

const { Api, JsonRpc, RpcError, JsSignatureProvider } = require('eosjs');
const fetch = require('node-fetch');
const { TextDecoder, TextEncoder } = require('text-encoding');

// Use your private (only for test enviroment!!!)
const signatureProvider = new JsSignatureProvider(ACCOUNT_ACTIVE_PRIVATE_KEY);

// http://localhost:8888 - the endpoint where the contract is deployed. 
// It can be a local node, JungleTestnet, Mainnet
const rpc = new JsonRpc("http://localhost:8888", { fetch });
const EOS = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });

async function getTableData(request, response) {
  const result = await rpc.get_table_rows({
    'code': ACCOUNT_NAME_DEPLOYED_THE_CONTRACT,
    'scope': ACCOUNT_NAME_DEPLOYED_THE_CONTRACT,
    'table': TABLE_NAME
  });

  console.log(result);
};

I hope this helps :)

  • It worked! Thanks a lot ;-) – Linda Dec 14 '18 at 14:52
  • What if I have large number of records in the table, could I filter/search by index? – Kristian Jan 7 at 12:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.