Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiSend example #2

Closed
pyramation opened this issue Jul 15, 2022 · 3 comments
Closed

multiSend example #2

pyramation opened this issue Jul 15, 2022 · 3 comments

Comments

@pyramation
Copy link
Collaborator

pyramation commented Jul 15, 2022

we may also need to do something special with the signingCosmosClient to make this easier:

an example from the community:

const {
  AminoTypes,
  SigningStargateClient
} = require('@cosmjs/stargate');
const { Registry } = require('@cosmjs/proto-signing');
const { defaultRegistryTypes } = require('@cosmjs/stargate');
const { OfflineSigner } = require('@cosmjs/proto-signing');
const { cosmos } = require('osmojs');

const getSigningCosmosClient = async ({ rpcEndpoint, signer }) => {
  // registry
  const registry = new Registry(defaultRegistryTypes);

  // aminotypes
  const aminoTypes = new AminoTypes({
    ...cosmos.bank.v1beta1.AminoConverter
  });

  cosmos.bank.v1beta1.load(registry);

  const client = await SigningStargateClient.connectWithSigner(
    rpcEndpoint,
    signer,
    { registry, aminoTypes }
  );

  return client;
};

module.exports = { getSigningCosmosClient: getSigningCosmosClient };

// #######################################

// ... and then in my index.js:

const {
  osmosis,
  ibc,
  cosmos,
  getSigningOsmosisClient,
  //getSigningCosmosClient,
  signAndBroadcast,
  FEE_VALUES
} = require('osmojs');

const { getSigningCosmosClient } = require('./cosmosclient.js');

/* ... */
@pyramation
Copy link
Collaborator Author

other examples that have simple flow https://gist.github.com/fadeev/a4981eff1cf3a805ef10e25313d5f2b7

@pyramation
Copy link
Collaborator Author

Here is the original index that impelled us to customize the signing client:

const { config } = require('./config/config.js');
const { generateSignerWallet } = require('./signer.js');

const {
  osmosis,
  ibc,
  cosmos,
  getSigningOsmosisClient,
  signAndBroadcast,
  FEE_VALUES
} = require('osmojs');

const { coin, coins } = require('@cosmjs/amino');

const {
  multiSend,
  send
} = cosmos.bank.v1beta1.MessageComposer.fromPartial;

/* TEST */

const amount = coins(1, 'uosmo');

const fee = FEE_VALUES.osmosis.swapExactAmountIn;

(async () => {
  const signer = await generateSignerWallet("osmosis", config.mnemonic).then((signer) => { return signer; });
  const address = await signer.getAccounts().then((accounts) => { return accounts[0].address; });

  const rpcEndpoint = config.rpcEndpoint;
  const client = await getSigningOsmosisClient({ rpcEndpoint, signer });

  const msg = send({
    fromAddress: address,
    toAddress: "osmo1REDACTED",
    amount: amount
  });

  console.dir(msg, { depth: null });
  /*
  prints the following:
  
  {
    typeUrl: '/cosmos.bank.v1beta1.MsgSend',
    value: {
      fromAddress: 'osmo1REDACTED',
      toAddress: 'osmo1osmo1REDACTED',
      amount: [ { denom: 'uosmo', amount: '1' } ]
    }
  }  
  */

  const res = await signAndBroadcast({
    client,
    chainId: 'osmosis-1',
    address: address,
    msgs: [msg],
    fee,
    memo: config.default_memo
  });

  /*
  nodejs crashes with error:
    C:\dev\user\test\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 (C:\dev\user\test\node_modules\@cosmjs\stargate\build\aminotypes.js:21:19)
        at C:\dev\user\test\node_modules\@cosmjs\stargate\build\signingstargateclient.js:207:60
        at Array.map (<anonymous>)
        at SigningStargateClient.signAmino (C:\dev\user\test\node_modules\@cosmjs\stargate\build\signingstargateclient.js:207:31)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
  */
  
  console.log(res);
})();

@ValarDragon
Copy link
Member

I'm actually proposing we make multi-send only allow one sender haha: cosmos/cosmos-sdk#12601

pyramation added a commit that referenced this issue Aug 2, 2023
fix type incompatible problem caused by bigint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants