osmosis-labs / osmojs

OsmosJS makes it easy to compose and broadcast Osmosis and Cosmos messages
https://cosmology.zone/products/osmojs
Apache License 2.0
63 stars 32 forks source link

About sending amount coins to an address problem #21

Closed d-never closed 1 year ago

d-never commented 1 year ago

I ran the following code according to the OsmoJS doc description, and an error occurred. What's the problem?

const signer = await getWalletFromMnemonic({mnemonic, token: 'OSMO'});
const client = await getSigningOsmosisClient({
    rpcEndpoint: rpcEndpoint,
    signer
});

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

const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;

const msg = send({
    amount: [
    {
        denom: 'uosmo',
        amount: '1000'
    }
    ],
    toAddress: address,
    fromAddress: address
});

const fee = {
    amount: [
    {
        denom: 'uosmo',
        amount: '864'
    }
    ],
    gas: '86364'
};
const response = await client.signAndBroadcast(address, [msg], fee);

err as follows:

/home/huzi/project/tx/node_modules/protobufjs/src/util/longbits.js:116
        ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
          ^

TypeError: util.Long is not a constructor
    at LongBits.toLong (/home/huzi/project/tx/node_modules/protobufjs/src/util/longbits.js:116:11)
    at Reader.read_uint64 [as uint64] (/home/huzi/project/tx/node_modules/protobufjs/src/reader.js:395:49)
    at Object.decode (/home/huzi/project/tx/node_modules/@cosmology/core/node_modules/osmojs/node_modules/cosmjs-types/cosmos/auth/v1beta1/auth.js:45:52)
    at SigningStargateClient.accountFromAny [as accountParser] (/home/huzi/project/tx/node_modules/@cosmology/core/node_modules/osmojs/node_modules/@cosmjs/stargate/build/accounts.js:33:62)
    at SigningStargateClient.getAccount (/home/huzi/project/tx/node_modules/@cosmology/core/node_modules/osmojs/node_modules/@cosmjs/stargate/build/stargateclient.js:109:35)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SigningStargateClient.getSequence (/home/huzi/project/tx/node_modules/@cosmology/core/node_modules/osmojs/node_modules/@cosmjs/stargate/build/stargateclient.js:119:25)
    at async SigningStargateClient.sign (/home/huzi/project/tx/node_modules/@cosmology/core/node_modules/osmojs/node_modules/@cosmjs/stargate/build/signingstargateclient.js:187:49)
    at async SigningStargateClient.signAndBroadcast (/home/huzi/project/tx/node_modules/@cosmology/core/node_modules/osmojs/node_modules/@cosmjs/stargate/build/signingstargateclient.js:167:23)
    at async file:///home/huzi/project/tx/core.js:41:18
pyramation commented 1 year ago

what version and what environment are you running? I'm not able to reproduce this.

Are you using typescript, babel, yarn workspace, or do you have a repo with a reproducible code I can look at?

d-never commented 1 year ago

what version and what environment are you running? I'm not able to reproduce this.

Are you using typescript, babel, yarn workspace, or do you have a repo with a reproducible code I can look at? It's running with Node.js V16.17.1. It doesn't make any difference to use this one. Will it be the problem?

pyramation commented 1 year ago

what version of osmojs?

do you have a codebase I can look at?

d-never commented 1 year ago

what version of osmojs?

do you have a codebase I can look at?

V0.32 image

d-never commented 1 year ago

what version of osmojs?

do you have a codebase I can look at?

Are different versions the cause of errors? Which version do you use?

pyramation commented 1 year ago

try osmojs@0.33.0 and let me know, I switched it back to import Long from 'long' and other TS fixes/cleanup.

d-never commented 1 year ago

osmojs@0.33.0

I updated to osmojs@0.33.0. There is a new error occurred.

/home/huzi/project/tx/node_modules/@cosmjs/stargate/build/aminotypes.js:21
            throw new Error(`Type URL '${typeUrl}' does not exist in the Amino message type register. ` +
                  ^

Error: Type URL '/cosmos.bank.v1beta1.MsgSend' 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.
    at AminoTypes.toAmino (/home/huzi/project/tx/node_modules/@cosmjs/stargate/build/aminotypes.js:21:19)
    at /home/huzi/project/tx/node_modules/@cosmjs/stargate/build/signingstargateclient.js:207:60
    at Array.map (<anonymous>)
    at SigningStargateClient.signAmino (/home/huzi/project/tx/node_modules/@cosmjs/stargate/build/signingstargateclient.js:207:31)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SigningStargateClient.signAndBroadcast (/home/huzi/project/tx/node_modules/@cosmjs/stargate/build/signingstargateclient.js:167:23)
    at async file:///home/huzi/project/tx/core.js:47:16
pyramation commented 1 year ago

are you still experiencing this issue in the latest version?

I'm not able to reproduce this. If possible, can you share a reproduce-able example repository I can clone and test?