Difference between revisions of "How-to: Interact with SNS canisters"

From Internet Computer Wiki
Jump to: navigation, search
(Created page with "If you want to interact with a dapp and the SNS DAO that governs the dapp, you likely know either the dapp canister ID or the SNS root canister ID by which an SNS is identifie...")
 
Line 9: Line 9:
 
=== DFX ===
 
=== DFX ===
 
  <nowiki> $ dfx canister --network small12 call nns-sns-wasm list_deployed_snses '(record {})' </nowiki>
 
  <nowiki> $ dfx canister --network small12 call nns-sns-wasm list_deployed_snses '(record {})' </nowiki>
 
  
 
=== Dashboard ===
 
=== Dashboard ===
Line 20: Line 19:
 
=== DFX ===
 
=== DFX ===
 
  <nowiki> $ dfx canister --network small12 call sns-root list_sns_canisters '(record {} )' </nowiki>
 
  <nowiki> $ dfx canister --network small12 call sns-root list_sns_canisters '(record {} )' </nowiki>
 
 
  
 
=== Dashboard ===
 
=== Dashboard ===
Line 30: Line 27:
 
=== DFX ===
 
=== DFX ===
 
  <nowiki> $ dfx canister --network small12 call sns-root get_sns_canisters_summary '(record {} )' </nowiki>
 
  <nowiki> $ dfx canister --network small12 call sns-root get_sns_canisters_summary '(record {} )' </nowiki>
 
  
 
=== Dashboard ===
 
=== Dashboard ===
Line 44: Line 40:
 
=== DFX ===
 
=== DFX ===
 
Download these snippets into an empty repo so that dfx can point at the correct testnet and correct canisters. This allows to call the canisters and read the output in a human friendly way.
 
Download these snippets into an empty repo so that dfx can point at the correct testnet and correct canisters. This allows to call the canisters and read the output in a human friendly way.
 
  
 
Snippet 1: [https://gitlab.com/-/snippets/2431348 dfx.json and candid files]
 
Snippet 1: [https://gitlab.com/-/snippets/2431348 dfx.json and candid files]
Line 52: Line 47:
 
=== DFX ===
 
=== DFX ===
 
  <nowiki> $ dfx canister --network small12 call sns-governance get_sns_initialization_parameters '(record {})' </nowiki>
 
  <nowiki> $ dfx canister --network small12 call sns-governance get_sns_initialization_parameters '(record {})' </nowiki>
 
  
 
=== Dashboard ===
 
=== Dashboard ===
Line 61: Line 55:
 
=== DFX ===
 
=== DFX ===
 
<nowiki> $ dfx canister --network small12 call sns-governance list_neurons '(record { of_principal=null; limit=100: nat32; start_page_at=null  } )' </nowiki>
 
<nowiki> $ dfx canister --network small12 call sns-governance list_neurons '(record { of_principal=null; limit=100: nat32; start_page_at=null  } )' </nowiki>
 
  
 
=== Dashboard ===
 
=== Dashboard ===
Line 70: Line 63:
 
=== DFX ===
 
=== DFX ===
 
  <nowiki> $ dfx canister --network small12 call sns-ledger icrc1_balance_of '(record { owner = principal "wmio3-kqaaa-aaaaa-aaasq-cai"; subaccount = null;})' </nowiki>
 
  <nowiki> $ dfx canister --network small12 call sns-ledger icrc1_balance_of '(record { owner = principal "wmio3-kqaaa-aaaaa-aaasq-cai"; subaccount = null;})' </nowiki>
 
  
 
=== Dashboard ===
 
=== Dashboard ===
Line 79: Line 71:
 
=== DFX ===
 
=== DFX ===
 
  <nowiki> $ dfx canister --network small12 call sns-ledger icrc1_balance_of '(record { owner = principal "w6ozc-gaaaa-aaaaa-aaarq-cai"; subaccount = opt vec {45;90;183;220;109;161;20;55;134;152;60;18;176;240;131;123;255;182;167;138;177;190;202;83;86;198;249;176;218;98;20;65}: opt vec nat8;})' </nowiki>
 
  <nowiki> $ dfx canister --network small12 call sns-ledger icrc1_balance_of '(record { owner = principal "w6ozc-gaaaa-aaaaa-aaarq-cai"; subaccount = opt vec {45;90;183;220;109;161;20;55;134;152;60;18;176;240;131;123;255;182;167;138;177;190;202;83;86;198;249;176;218;98;20;65}: opt vec nat8;})' </nowiki>
 
  
 
=== Dashboard ===
 
=== Dashboard ===
 
On the dashboard, navigate to the SNS ledger canister by entering the canister ID in the search bar. Then, click ‘+’ next to <syntaxhighlight inline>icrc1_balance_of</syntaxhighlight>, and provide as the argument TODO. Then press “Call”.
 
On the dashboard, navigate to the SNS ledger canister by entering the canister ID in the search bar. Then, click ‘+’ next to <syntaxhighlight inline>icrc1_balance_of</syntaxhighlight>, and provide as the argument TODO. Then press “Call”.

Revision as of 15:52, 21 November 2022

If you want to interact with a dapp and the SNS DAO that governs the dapp, you likely know either the dapp canister ID or the SNS root canister ID by which an SNS is identified. We first describe how starting from SNS root canister ID you can find and interact with all SNS and dapp canisters.

Finding all SNS and dapp canisters - starting from SNS

Get the SNS root canister. The SNS root canister is the SNS canister that knows about and controls all the other SNS canisters and the dapp canisters. Therefore it is the canister by which an SNS can be identified. Given this canister ID you can verify it is indeed an “official SNS” that runs a SNS wasm that has been vetted by the NNS. All SNS root canisters, and thus all SNSs, are listed in the NNS canister called SNS wasm modules canister, or SNS-W for short. SNS-W is a fixed canister ID in the NNS subnet and its canister ID is qaa6y-5yaaa-aaaaa-aaafa-cai. Call the method list_deployed_snses and find all root canister IDs in the returned list. You can now check that the SNS root canister ID you knew is one of them.

DFX

 $ dfx canister --network small12 call nns-sns-wasm list_deployed_snses '(record {})' 

Dashboard

In the SNS-W canister interface, click ‘+’ next to list_deployed_snses, and then click “Call”.

Get all SNS and dapp canister IDs. From the last step, you know that the root canister ID has been verified as a “true” SNS root canister ID deployed through the blessed canister wasm path. You can next get the rest of the canister IDs associated with that SNS by calling list_sns_canisters on the SNS root canister. This list contains a list of all canisters that collectively make up the SNS. The response from this method also has a “dapps” entry that lists the dapp canisters that are governed by the SNS.

DFX

 $ dfx canister --network small12 call sns-root list_sns_canisters '(record {} )' 

Dashboard

On the dashboard, enter the canister ID of SNS root in the search tab. You should see all the methods of SNS root now. Similarly to the last step, click ‘+’ next to list_sns_canisters, and then click “Call”.

Get the summary of all SNS and dapp canisters. Finally, you can get the summary and ownership graph of the SNS including the dapps. To do so, call get_sns_canisters_summary on the SNS root canister. This will return the status of each canister in the SNS, including information such as the canister’s controller and cycles balance.

DFX

 $ dfx canister --network small12 call sns-root get_sns_canisters_summary '(record {} )' 

Dashboard

On the dashboard, where you should still be in the SNS root canister interface from the last Step, click ‘+’ next to get_sns_canisters_summary, and then click “Call”.

Look at the dapp canisters.

Finding all SNS and dapp canisters - starting from the dapp

If you have a dapp canister ID, you can first query the canister to find its controller. If the dapp is controlled by an SNS, then this will return you the SNS root canister ID and you can then proceed as explained in the section above.

Inspecting the SNS canisters

Preparation

DFX

Download these snippets into an empty repo so that dfx can point at the correct testnet and correct canisters. This allows to call the canisters and read the output in a human friendly way.

Snippet 1: dfx.json and candid files

Check the initialization parameters. The SNS governance canister stores all the initial parameters that were provided to SNS-W when the SNS was first installed. SNS governance can be queried for this information to learn how the SNS was set up. This information includes the initial token distribution, as well as the initial neurons, consisting of developer and airdrop neurons.

DFX

 $ dfx canister --network small12 call sns-governance get_sns_initialization_parameters '(record {})' 

Dashboard

On the dashboard, navigate to the SNS governance canister by entering the canister ID in the search bar. Then, click ‘+’ next to get_sns_initialization_parameters, and click “Call”.

List the neurons that exist in SNS Governance. Before the decentralization sale finishes, the only neurons are the developer and airdrop neurons. Thus, you can look at all neurons and see that they match the initialization that you saw in Step 1.

DFX

$ dfx canister --network small12 call sns-governance list_neurons '(record { of_principal=null; limit=100: nat32; start_page_at=null } )'

Dashboard

On the dashboard, navigate to the SNS governance canister by entering the canister ID in the search bar. Then, click ‘+’ next to list_neurons, and click “Call”.

Check out how many tokens are sold in the decentralization sale. As long as the SNS has not launched yet, there are some tokens reserved for the SNS decentralization sale. They are stored in the SNS ledger account that is owned by the SNS sale canister (previously called swap). Thus, to learn how many tokens are in the decentralization sale, call icrc1_balance_of to get the balance of the Swap canister. The returned value is given in fractions of 10E-8 of an SNS token.

DFX

 $ dfx canister --network small12 call sns-ledger icrc1_balance_of '(record { owner = principal "wmio3-kqaaa-aaaaa-aaasq-cai"; subaccount = null;})' 

Dashboard

On the dashboard, navigate to the SNS ledger canister by entering the canister ID in the search bar. Then, click ‘+’ next to icrc1_balance_of, and provide as the argument the ID of the SNS ledger canister. Then press call.

Learn how much tokens are in the SNS treasury. The SNS treasury is a SNS ledger account that is owned by SNS governance. Specifically, it is on a defined subaccount of the SNS governance’s ledger account. To learn it, use icrc1_balance_of to get the balance of the SNS ledger account with the following arguments:

DFX

 $ dfx canister --network small12 call sns-ledger icrc1_balance_of '(record { owner = principal "w6ozc-gaaaa-aaaaa-aaarq-cai"; subaccount = opt vec {45;90;183;220;109;161;20;55;134;152;60;18;176;240;131;123;255;182;167;138;177;190;202;83;86;198;249;176;218;98;20;65}: opt vec nat8;})' 

Dashboard

On the dashboard, navigate to the SNS ledger canister by entering the canister ID in the search bar. Then, click ‘+’ next to icrc1_balance_of, and provide as the argument TODO. Then press “Call”.