To allow an account to execute messages on behalf of another (using authz), you must first establish a grant.
Using FetchD CLI
Use the fetchd tx authz grant command to authorize a specific message type:
fetchd tx authz grant $(fetchd keys show grantee --output json | jq -r .address) generic --msg-type "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission" --from=$(fetchd keys show grantor --output json | .address) --gas auto --gas-adjustment 1.5 --gas-prices 5000000000atestfet
Using Python
If you have access to the keys in Python, use MsgGrant with a Grant object containing a GenericAuthorization and an expiration Timestamp.
from cosmpy.aerial.client import LedgerClient, NetworkConfig
from cosmpy.aerial.wallet import LocalWallet
from cosmpy.aerial.tx import Transaction
from cosmpy.aerial.client.utils import prepare_and_broadcast_basic_transaction
from cosmpy.crypto.keypairs import PrivateKey
from cosmpy.protos.cosmos.distribution.v1beta1.tx_pb2 import MsgWithdrawValidatorCommission
from cosmpy.protos.cosmos.authz.v1beta1.tx_pb2 import MsgGrant
from cosmpy.protos.cosmos.authz.v1beta1.authz_pb2 import GenericAuthorization, Grant
from google.protobuf import any_pb2, timestamp_pb2
from datetime import datetime, timedelta
client = LedgerClient(NetworkConfig.fetchai_dorado_testnet())
wallet = LocalWallet(PrivateKey("rBDA3Q0vK5T+JVQmXSoooqUY/mSO4mmhMHQJI31+h1o="))
validator = LocalWallet(PrivateKey("<redacted>private key of dorado validator0"))
# Prepare authorization
authz_any = any_pb2.Any()
authz_any.Pack(
GenericAuthorization(
msg="/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission"
),
"",
)
expiry = timestamp_pb2.Timestamp()
expiry.FromDatetime(datetime.now() + timedelta(seconds=60))
grant = Grant(authorization=authz_any, expiration=expiry)
# Create the grant message
msg = MsgGrant(
granter=str(validator.address()),
grantee=str(wallet.address()),
grant=grant,
)
tx = Transaction()
tx.add_message(msg)
tx = prepare_and_broadcast_basic_transaction(client, tx, validator)
tx.wait_to_complete()