0

I have three smart contracts (A, B, C) and one account (X). As the requirement is I just need only one authority (administrator) who is going to manage all these smart contracts data. So I deployed these smart contracts using the same account. Whenever I need to manage data from table I need to deploy the particular smart contract first. For eg.

A, B and C smart contracts are deployed using account X. Data in multi-index tables are saved respectively. In Latest, C is deployed so now X can only access multi-index table and Actions of C. Now, if I want to manage data of A smart contract, at this level for accessing the table and Actions of A I need to deploy A again. So, the table is in X's abi and can access now. Similarly for B.

Otherwise it gives error as,

Error 3060003: Contract Table Query Exception
Most likely, the given table doesn't exist in the blockchain.
Error Details:
Table documents is not specified in the ABI

My question is every time I need to manage data of any table, do I need to deploy its smart contract first? I don't want three different accounts for A, B and C. Please guide and suggest.

1

You can deploy only one contract per account. If you deploy new contract on your account, existing contract is removed, but its data saved via multi_index table are alive. You need to merge three contracts into one.

Easiest way to do this is putting all methods of three contracts into one class.

Second, you can use multiple contract classes in one wasm, but you need to write down your own apply() function to dispatch action correctly. apply() is an entry point of eosio contract like main(), and it would be generated automatically unless you declare it explicitly. Refer to here. This way requires advanced knowledge about eos contract compilation, or you will fail to generate ABI correctly.

Third, you don't like it, but you can make three accounts and set admin account's active to each account's active permission instead of key.

contract1:
  permission:
    active: 1 1 admin@active
            1 1 EOS8BQAdzgacbacUjuUwYR1wEMUcEPLu1DpucmD4xNSLhtXuDSAHe

contract2:
  permission:
    active: 1 1 admin@active

...
| improve this answer | |
  • For the third option, In each smart contract, I need to check the authority bypassing admin account name. Now I am doing require_auth(_self);. Am I correct? – Varsh May 29 at 7:47
  • Yes, but you need to sign transaction with key of admin@active, but send action with contract1@active. (If you want to send action to contract1) If you don't want to do that, you can hard-code require_auth("admin_account_name"_n); or make a singleton to store admin account name. – conr2d May 29 at 19:31
  • Okay thank you! – Varsh Jun 8 at 2:14
  • Can you please guide on the second option? – Varsh Jun 18 at 6:42
  • Refer here. This is a very simple example. Please NEVER try this in product until you understand its behavior completely. There was a theft that EOS worth $100K was stolen because of insecure dispatcher. – conr2d Jun 18 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.