Mykle Hansen
Mykle Hansen

Reputation: 552

Can I query a Near contract for its method signatures?

Is there a way to query what methods are offered by a given NEAR contract? (So that one could do autodiscovery of some standard interface, for instance.) Or do you have to just know the method signatures already before you can interact with a contract?

Upvotes: 3

Views: 143

Answers (4)

Marcelo Fornet
Marcelo Fornet

Reputation: 583

NEP-351 was recently approved, which provides a mechanism for contracts to expose all standards they implement. However, it is up to contract developers to follow this NEP. When integrated into the main SDK, I presume most will.

Alternatively, there is a proposal to create a global registry as a smart contract that provides this information.

Upvotes: 1

amgando
amgando

Reputation: 1591

I suppose you can just include a method in your own contracts that returns the other method signatures in some useful format: json or whatever

you would have to make sure that it stays current by maybe writing some unit tests that use this method to exercise all others

I suppose this interface (method and unit tests) can be standardized as an NEP in the short term until our interface becomes discoverable. any contracts that adhere to this NEP must include this "tested reflection method" or "documentation method" or whatever it would be called

Upvotes: 0

sirwillem
sirwillem

Reputation: 722

No not yet. Currently all contract methods have the same signature. () -> () No arguments and nothing is returned. Each method has a wrapper function that deserializes the input bytes from a host; calls the method; and serializes the return value and passes the bytes back to the host.

This is done with input and value_return. See input..

There are plans to include the actual signatures of the methods in the binary in a special section, which would solve this issue.

Upvotes: 2

Josh Ford
Josh Ford

Reputation: 326

Currently, there is not.

You will need to know what contract methods are available in order to interact with a smart contract deployed on NEAR. Hopefully, the ability to query available methods will be added in the near future.

Upvotes: 0

Related Questions