Skip to content

Request: Include cosmos.authz.v1beta1.MsgGrant in Default Amino Message Registry #1931

@kowshikvajrala

Description

@kowshikvajrala

Please consider adding support for
/cosmos.authz.v1beta1.MsgGrant
to the default Amino message.

I am attempting to grant authorization (Authz) for validator commission withdrawal using CosmJS with Amino signing.

import 'dotenv/config';
import { SigningStargateClient } from '@cosmjs/stargate';
import { LedgerSigner } from '@cosmjs/ledger-amino';
import { makeCosmoshubPath } from '@cosmjs/amino';
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
import { GenericAuthorization } from 'cosmjs-types/cosmos/authz/v1beta1/authz';
import { MsgGrant } from 'cosmjs-types/cosmos/authz/v1beta1/tx';

// ---- ENV ----
const RPC_URL = process.env.RPC_URL;
const BECH32_PREFIX = process.env.BECH32_PREFIX;
const GRANTEE_ADDRESS = process.env.GRANTEE_ADDRESS;
const FEE_DENOM = process.env.FEE_DENOM;

// ---- Ledger & client setup ----
console.log('Connecting to Ledger...');
// Handle CommonJS/ESM interop
const transportConstructor = TransportNodeHid.default || TransportNodeHid;
const transport = await transportConstructor.open();
const signer = new LedgerSigner(transport, {
    hdPaths: [makeCosmoshubPath(0)],
    prefix: BECH32_PREFIX,
});

const [account] = await signer.getAccounts();
const GRANTER_ADDRESS = account.address;

console.log('Granter address (Ledger):', GRANTER_ADDRESS);

const client = await SigningStargateClient.connectWithSigner(RPC_URL, signer);

// ---- Action: Grant Withdraw Commission Authorization ----
export async function grantWithdrawCommission() {

    // Authorization Type
    const msgTypeUrl = '/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission';

    // Expiration: 10 years from now
    const expirationDate = new Date();
    expirationDate.setFullYear(expirationDate.getFullYear() + 10);

    // Construct Timestamp manually
    const expiration = {
        seconds: BigInt(Math.floor(expirationDate.getTime() / 1000)),
        nanos: (expirationDate.getTime() % 1000) * 1000000,
    };

    // MsgGrant Type URL
    const grantMsgTypeUrl = '/cosmos.authz.v1beta1.MsgGrant';

    const grantMsg = {
        typeUrl: grantMsgTypeUrl,
        value: MsgGrant.fromPartial({
            granter: GRANTER_ADDRESS,
            grantee: GRANTEE_ADDRESS,
            grant: {
                authorization: {
                    typeUrl: '/cosmos.authz.v1beta1.GenericAuthorization',
                    value: GenericAuthorization.encode(
                        GenericAuthorization.fromPartial({
                            msg: msgTypeUrl,
                        }),
                    ).finish(),
                },
                expiration: expiration,
            },
        }),
    };

    const fee = {
        amount: [{ denom: FEE_DENOM, amount: '5000' }],
        gas: '200000',
    };

    console.log(
        `Granting 'MsgWithdrawValidatorCommission' to ${GRANTEE_ADDRESS}...`,
    );
    console.log('Please sign the transaction on your Ledger device.');

    try {
        const result = await client.signAndBroadcast(
            GRANTER_ADDRESS,
            [grantMsg],
            fee,
        );

        console.log('Tx result:', result);

        if (result.code !== 0) {
            console.error('Transaction failed:', result.log || result.rawLog);
        }

    } catch (error) {
        console.error('Error granting commission withdrawal:', error);
    }
}

await grantWithdrawCommission();

Which resulting in:

Error granting commission withdrawal: Error: Type URL '/cosmos.authz.v1beta1.MsgGrant' does not exist in the Amino message type register. If you need support for this message type, you can pass in additional entries to the AminoTypes constructor. If you think this message type should be included by default, please open an issue at https://github.com/cosmos/cosmjs/issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions