tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
413 stars 271 forks source link

updateAccountPermissions fail Failed to sign transaction: Invalid transaction provided #443

Closed trybye closed 2 months ago

trybye commented 9 months ago

    async AccountPermissionUpdate(){

        try {

              let ownerPermission = { type: 0, permission_name: 'owner' };
            ownerPermission.threshold = 2;
            ownerPermission.keys  = [];

            let activePermission = { type: 2, permission_name: 'active0' };
            activePermission.threshold = 2;
            activePermission.operations = '7fff1fc0037e0000000000000000000000000000000000000000000000000000';
            activePermission.keys = [];
            console.log('account:',this.value); //this.value is the default address

            ownerPermission.keys.push({ address: this.value, weight: 1 });
            ownerPermission.keys.push({ address: 'TKPQvfHQnPyEhqfebfqaUrz9FaJ2Zsnty8', weight: 1 });
            activePermission.keys.push({ address: this.value, weight: 1 });
            activePermission.keys.push({ address: 'TKPQvfHQnPyEhqfebfqaUrz9FaJ2Zsnty8', weight: 1 });

            let tx = await tronWeb.transactionBuilder.updateAccountPermissions(this.value, ownerPermission, null, [activePermission]);

            let signedTxx = await tronWeb.trx.sign(tx);

            let broastTx = await tronWeb.trx.sendRawTransaction(signedTxx);

        } catch (error) {
          console.log(error);
        }

    }

catch error Failed to sign transaction: Invalid transaction provided

svein1010 commented 9 months ago

address parameter in permission.keys should be in hex format.

-   ownerPermission.keys.push({ address: this.value, weight: 1 });
-   ownerPermission.keys.push({ address: 'TKPQvfHQnPyEhqfebfqaUrz9FaJ2Zsnty8', weight: 1 });
-   activePermission.keys.push({ address: this.value, weight: 1 });
-   activePermission.keys.push({ address: 'TKPQvfHQnPyEhqfebfqaUrz9FaJ2Zsnty8', weight: 1 });
+   ownerPermission.keys.push({ address: tronWeb.address.toHex(this.value), weight: 1 });
+   ownerPermission.keys.push({ address: tronWeb.address.toHex('TKPQvfHQnPyEhqfebfqaUrz9FaJ2Zsnty8'), weight: 1 });
+   activePermission.keys.push({ address: tronWeb.address.toHex(this.value), weight: 1 });
+   activePermission.keys.push({ address: tronWeb.address.toHex('TKPQvfHQnPyEhqfebfqaUrz9FaJ2Zsnty8'), weight: 1 });

Sorry for any inconvenience . We will update our documentation.

Ocea91 commented 9 months ago

Only hexstring is supported for the address, not in base58 format.

start940315 commented 3 months ago

Base58 format is supported in TronWeb@6.0.0-beta.3, please install this version to try this feature:

npm install tronweb@beta