cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
635 stars 328 forks source link

How to create msg for msgGrant #1534

Closed tungle-notional closed 6 months ago

tungle-notional commented 7 months ago

I'm using nodejs to create a msgGrant with a custom authorization and a function in my smart contract deployed on cosmwasm. I'm trying smt like this:

let data = {
        grants: [
            {
                contract: 'migaloo14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s58v48z',
                limit: {
                    typeUrl: '/cosmwasm.wasm.v1.CombinedLimit',
                    value: Buffer.from(JSON.stringify({
                        calls_remaining: 1000,
                        amounts: [
                            {
                                denom: 'token',
                                amount: 250
                            }
                        ]
                    }))
                },
                filter: {
                    typeUrl: '/cosmwasm.wasm.v1.AcceptedMessageKeysFilter',
                    value: Buffer.from(JSON.stringify({
                        keys: [
                            'create_pair'
                        ]
                    }))
                }
            }
        ]
    }

    const msg = {
        typeUrl: "/cosmos.authz.v1beta1.MsgGrant",
        value: MsgGrant.fromPartial({
            grantee: "migaloo1sxpxhzprejg5rgth0k74ws782mw00ten640zl0",
            granter: "migaloo1s5898aa2tj0yaccg3xwewv3dft3q5nf8x7fvr8",
            grant: {
                authorization: {
                    typeUrl: '/cosmwasm.wasm.v1.ContractExecutionAuthorization',
                    value: Buffer.from(JSON.stringify(data))
                },
                expiration: null
            }
        }),
    }
    await signingClient.signAndBroadcast(alice, [msg], { gas: "100000", amount: [{ amount: "1000", denom: "token" }] })

I have this error: errUnknownField "*types.ContractExecutionAuthorization": {TagNum: 15, WireType:"start_group"}: tx parse error. Can you give me any example?

nooxx commented 6 months ago

hey @tungle-notional would you mind sharing how you got it working? 🙏