How to load contract ABI in JavaScript

565 Views Asked by At

Currently near-js-sdk and create-near-app show how to manually define your contract interface in JavaScript:

From main.test.js ( https://github.com/near/create-near-app/blob/master/templates/react/src/main.test.js#L5 ):

  window.contract = await near.loadContract(nearConfig.contractName, {
    viewMethods: ['get_greeting'],
    changeMethods: [],
    sender: window.accountId
  })

However it is cumbersome to manually describe contract interface. How to make NEAR to load contract ABI information directly from the compiler files produced by cargo build?

1

There are 1 best solutions below

2
On BEST ANSWER

We don't generate ABI for contracts yet since we want to support all languages that compile to Wasm, which would make it really hard to define language-agnostic ABI. However, we have experimented with some ideas: https://github.com/near/borsh/tree/master/borsh-rs/borsh-schema-derive-internal however, they are far from being integrated.