0

I am trying to set the eosio.code permission for my contract on account kbo2byvpkbiy (private blockchain). The reason I want to do this is calling eosio.token/transfer from within this contract.

All I have figured out so far is the following code:

await contractApi.transact({
    actions: [{
        account: 'eosio',
        name: 'updateauth',
        authorization: [{
            actor: "kbo2byvpkbiy", 
            permission: 'active',
        }],
        data: {
            account: "kbo2byvpkbiy",  
            permission: "active",
            parent: 'active',
            auth: {
                "threshold": 1,
                "keys": [{
                    "key": "EOS6gmCFLGxcAkKRskJKBPwXdFwZSJ7TPz2RRpXU1Lyn5e3zXrEFm",
                    "weight": 1
                }],
                "accounts": [{
                    "permission": {
                        "actor": "kbo2byvpkbiy",
                        "permission": "eosio.code"
                    },
                    "weight": 1
                }],
                "waits": [
                    {
                        "wait_sec": 0,
                        "weight": 0
                    }
                ]
            }
        }
    }]
}, {
    blocksBehind: 3,
    expireSeconds: 30,
});

When I use this I get the following error:

Error: Cannot set an authority as its own parent at new RpcError 

What am I doing wrong? The correct cleos command (after importing the private key into my wallet is:

cleos set account permission kbo2byvpkbiy active '{"threshold": 1,"keys": [{"key": "EOS6gmCFLGxcAkKRskJKBPwXdFwZSJ7TPz2RRpXU1Lyn5e3zXrEFm","weight": 1}],"accounts": [{"permission":{"actor": "kbo2byvpkbiy","permission":"eosio.code"},"weight":1}]}'

But how do I do this correctly in eosjs?

0

1. Option
Get your account data from the chain. The result should contain required_auth.accounts property. Push to that array an object like

{ permission: { actor: accountName, permission: 'eosio.code' }, weight }

Once pushed update your account on chain like this

eosjs.transaction(tr => {
        tr.updateauth({
            account: 'Your account name',
            permission: 'active',
            parent: 'owner',
            auth: 'The updated **required_auth** object'
        }, { authorization: [Your account name@active] });

  }, { broadcast: true, sign: true, keyProvider: 'Private key of your account' });

2. Option
In your provided object

 data: {
            account: "kbo2byvpkbiy",  
            permission: "active",
            parent: 'active',
            auth: {
                "threshold": 1,
                "keys": [{
                    "key": "EOS6gmCFLGxcAkKRskJKBPwXdFwZSJ7TPz2RRpXU1Lyn5e3zXrEFm",
                    "weight": 1
                }],
                "accounts": [{
                    "permission": {
                        "actor": "kbo2byvpkbiy",
                        "permission": "eosio.code"
                    },
                    "weight": 1
                }],
                "waits": [
                    {
                        "wait_sec": 0,
                        "weight": 0
                    }
                ]
            }
        }

Set parent prop to 'owner' instead of 'active'

3. Option

Check out eoslime as it is based on eosjs. There is account.addPermission('eosio.code') method. You could check out their code to figure out how they do it

| improve this answer | |

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.