Sputnik v2 throws "account doesn't exist" error when creating contract, adding account doesn't fix it. Tips?

73 views Asked by At

I am upgrading the DAO to use version 4 of the near sdk. During the migration I needed to change the way the AccountId struct was used, from being a string to being a struct that holds a string.

The original test has a token id of an empty string, "" assigned to a const which cannot be converted to a struct instance because instantiating a struct isn't constant. An empty string "" now raises a panic because it isn't a proper account id (it must have lowercase letters and numbers with a period, among other things).

I changed it to base.token and added constructors where there were strings before.

Here is my code: https://github.com/roshkins/sputnik-dao-contract

I'm getting this error:

---- test_multi_council stdout ----
thread 'test_multi_council' panicked at 'Outcome ExecutionOutcome {     
    logs: [],
    receipt_ids: [
        `6MxMk3XY6o2VnL4DucLADm86gUJPJHDfecQQ9hUDA72X`,
        `7k1jV711STFLKdbznRCvXr27UxJ2WwgZfnoGiZiFrEKm`,
    ],
    burnt_gas: 2428070807578,
    tokens_burnt: 242807080757800000000,
    status: Failure(Action #0: Can't complete the action because account "base.token" doesn't exist),

If I add an account called "base.token" it throws an error because it's a sub account. I tried changing the accountid of the contract to base.token that also throws that error. Any help?

Edit: I was able to add the following code to change the root account name to base.token: let mut gen_cfg = GenesisConfig::default(); gen_cfg.init_root_signer(base_token().as_str());

I get a slightly different error now:

thread 'test_multi_council' panicked at 'Outcome ExecutionOutcome {
    logs: [],
    receipt_ids: [
        `6MxMk3XY6o2VnL4DucLADm86gUJPJHDfecQQ9hUDA72X`,
        `7k1jV711STFLKdbznRCvXr27UxJ2WwgZfnoGiZiFrEKm`,
    ],
    burnt_gas: 2428070807578,
    tokens_burnt: 242807080757800000000,
    status: Failure(Action #0: cannot find contract code for account base.token),
} was a failure',
1

There are 1 answers

1
Josh Ford On

For sub-accounts, you can only create an account if you have keys to the root account. So if you owned token TLA (top-level account) you could create base.token. So you could have token.near as an accountId and then you would be able to create base.token.near. Does that make sense?

Here is some more info on the account model: https://docs.near.org/docs/concepts/account#subaccounts