2

I am trying to create an account using eosjs in node.js. I am using :

eos = Eos({keyProvider});
eos.transaction(tr => {
        tr.newaccount({
            creator: 'eosio',
            name: 'account1',
            owner: pubkey,
            active: pubkey
        })

With this eos instance, I am successfully calling the getblock api. WHile hitting this api, i get the error:

{"code":500,"message":"Internal Service Error","error":{"code":3090003,"name":"unsatisfied_authorization","what":"Provided keys, permissions, and delays do not satisfy declared authorizations","details":[]}}

Error is same on nodeos console too. I tried some solutions available out there bu they didn't work for me. I am accessing local node running on same system. Please let me know the resolution of this error.

4 Answers 4

1

You need to sign the transaction you can do it by

 eosConfig = {keyProvider: ['YOUR_CREATOR_PRIVATE_KEY']}
 let eos = Eos(eosConfig)
 eos.transaction(tr => {
        tr.newaccount({
            creator: 'eosio',
            name: 'account1',
            owner: pubkey,
            active: pubkey
        }) \.then( (resp) =>{
      console.log("EOS resp ", resp);}); 

As you are on localnet then you need only one parameter to pass in eosConfig which is keyProvider.

9
  • Yes i have done that. To ensure the correctness of eos instance, i have written in question that i am able to access getblock and similar apis. Thanks for your consideration.
    – A.K.
    Commented Sep 24, 2018 at 5:59
  • I also updated it in the question @Mr.Y
    – A.K.
    Commented Sep 24, 2018 at 6:08
  • yes you will be able to call getblock because getblock action don't need authorization but if you want to do transaction then you need authorization and that will be done by only providing private key to key provider.
    – Mr.Y
    Commented Sep 24, 2018 at 8:28
  • Yes, i have tried to add authorization in the instance creation and in transaction both, it is not working anyway. Have you tried account creatoin using eosjs successfully?
    – A.K.
    Commented Sep 24, 2018 at 8:43
  • 1
    yes you need to provide private key of eosio
    – Mr.Y
    Commented Sep 24, 2018 at 10:42
2

You need to add an authority to eosconfig, e.g.:

eos = Eos({
    keyProvider,
    authorization: EOSIO_ACCOUNT_NAME + '@active',
  });
7
  • no luck, same error. I have also tried putting options in transaction too like this: github.com/EOSIO/eosjs#options
    – A.K.
    Commented Sep 24, 2018 at 8:05
  • then it is a problem with your account names, maybe you have a typo somewhere?
    – friedger
    Commented Sep 24, 2018 at 8:17
  • I have checked each and everything. Have you tried creation of account using eosjs? @friedger
    – A.K.
    Commented Sep 24, 2018 at 8:18
  • @A.K. That works for me: let eos = Eos({ keyProvider: DOCTORS_KEY, // private key httpEndpoint: HTTP_CHAIN_API_ENDPOINT, chainId: CHAIN_ID, authorization: DOCTORS_ACCOUNT_NAME + '@active', }); eos.newaccount({ creator: DOCTORS_ACCOUNT_NAME, name: THE_NEW_NAME, owner: DOCTORS_ACCOUNT_NAME, active: DOCTORS_ACCOUNT_NAME }).then(r => console.log("ok: " + r)) .catch(e => console.log("err:" + e))
    – friedger
    Commented Sep 24, 2018 at 9:15
  • Are you sure that no transaction creation is needed and in this line owner: DOCTORS_ACCOUNT_NAME, active: DOCTORS_ACCOUNT_NAME , we will be putting the name not the key?
    – A.K.
    Commented Sep 24, 2018 at 10:10
1

I had the same error shown when performing an action on a test network, and I solved it updating my permissions launching this single cmd:

cleos.sh set account permission <your-account> active '{"threshold":1,"keys":
[{"key":"<your-public-key>","weight":1}],"accounts":
[{"permission":{"actor":"<your-account>","permission":"eosio.code"},"weight":1}]}' 
owner -p <your-account>@owner

Hope this can help you, but actually needs an account to be done.

5
  • I hope for this command account should be already there. I am trying to create one. Please add more details.
    – A.K.
    Commented Sep 21, 2018 at 11:23
  • Are you working with the mainnet or with the Jungle Testnet? Commented Sep 21, 2018 at 11:25
  • localnet , i mean a nodeos running locally on my machine
    – A.K.
    Commented Sep 21, 2018 at 11:25
  • 1
    Never worked on the local, but here I find some stuff that can be interesting for you: github.com/EOSIO/eos/issues/4289. Check answers from daithi-coombes Commented Sep 21, 2018 at 11:29
  • That thread is interesting although i have created account using cleos on terminal, now i am looking to do the same using code
    – A.K.
    Commented Sep 21, 2018 at 12:05
1

Try this code

    eos = Eos({ keyProvider : "PR_KEY"});

eos.transaction({
              actions: [
                  {
                      name: "newaccount",
                      account:"cat",
                      authorization:[{
                          actor:'cat',
                          permission: 'active'
                      }],
                      data: {
                          creator:"cat",
                          name:"newaccount",
                          owner: "PUB_KEY",
                          active: "PUB_KEY"
                      }
                  },
              ]
            }).then(res => {
                console.log(res);
            });
2
  • please change cat with eosio
    – Mr.Y
    Commented Sep 24, 2018 at 10:42
  • It was working too after putting the right private key.
    – A.K.
    Commented Sep 24, 2018 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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