Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List all deployed contracts/tokens? #748

Open
imanov opened this issue Aug 5, 2022 · 7 comments
Open

List all deployed contracts/tokens? #748

imanov opened this issue Aug 5, 2022 · 7 comments
Labels
question Further information is requested

Comments

@imanov
Copy link

imanov commented Aug 5, 2022

Is there a way to get/search/track all deployed custom tokens/smart contracts in a private blockchain ?
Is it possible to do it through an RPC command?

I see that there is a ListContracts method in ContractManagement class, but I was not able to find a way to use/call it from a remote client.

@imanov imanov added the question Further information is requested label Aug 5, 2022
@roman-khimov
Copy link
Contributor

get/search

NeoGo allows to iterate over contract IDs with getcontractstate (https://github.com/nspcc-dev/neo-go/blob/41613cd631e662dab1791adc306f53faddb17b89/docs/rpc.md#getcontractstate), but you don't reliably know where to stop. Still, it's possible and then you can look into manifested standards (but neo-project/neo#1883, so additional checks are needed).

findstates can probably be used as well, though that'd be a bit more involved.

track

Deploy notifications are emitted from ContractManagement contract for every deployment (see Update and Destroy also).

@imanov
Copy link
Author

imanov commented Aug 8, 2022

Is there a problem to add a ListContracts method to RpcServer, which uses the one that is already available in ContractManagement?

@ixje
Copy link
Contributor

ixje commented Aug 16, 2022

findstates can probably be used as well, though that'd be a bit more involved.

To elaborate a bit on the steps, as I recently needed this myself, and is probably going to take some time to get accepted (if at all).

  1. Get the chain height using the getblockcount RPC method
  2. Get the stateroot using the height from 1. using the getstateroot RPC method
  3. Call the findstates RPC method with
{
  "jsonrpc": "2.0",
  "method": "findstates",
  "params": ["<your_state_root_here>","0xfffdc93764dbaddd97c48f252a53ea4643faa3fd","CA=="],
  "id": 1
}
  1. iterate over results
    a. base64decode the value field
    b. deserialize the result using binaryserializer to get a stackitem
    c. feed the stackitem from b. into this method to get the contract state from which you can access the manifest and NEF.
  2. check if truncated is true, if so take the last key from the results and append it as the 4th argument to the params field to get the next page of results

@imanov
Copy link
Author

imanov commented Aug 16, 2022

As I mentioned in my question, there is already a native method ListContracts. It can be just exposed as a RPC method. It returns all registered contracts (including native ones) and could also have some filter options.

@cschuchardt88
Copy link
Member

If i were to implement "FindContractLog" in RPC for #807 you would be able to do a search for "Deploy" event on the ContractManagement (0xfffdc93764dbaddd97c48f252a53ea4643faa3fd), than page through looking for a contract. But who knows when that will come out.

@vncoelho
Copy link
Member

vncoelho commented Aug 16, 2023

The ContractManagement returns an iterator for all hashes that are non-native with GetContractHashes.

However, I think that there could be other methods more directed to this on the RPC calls themself.

@cschuchardt88
Copy link
Member

This would require you to get all contracts and on the blockchain. Check for Nep-17, Nep-11 in the supportedStandards property of the contract manifest. Then you can invoke the virtual machine to get it's standards. Like symbol decimals balanceOf for example. This last step isn't necessary, but it also depends on how confident you want to be that the contract does indeed follow the specification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants