Protobuf interfaces for Agoric on Cosmos
npm install @agoric/cosmic-proto
TODO #9200
Import the agoric object from the Agoric bundle.
import { agoric } from '@agoric/cosmic-proto/agoric/bundle.js';
const {
    installBundle,
} = agoric.swingset.MessageComposer.withTypeUrl;
⚡️ For web interfaces, we recommend using cosmos-kit. Continue below to see how to manually construct signers and clients.
Here are the docs on creating signers in cosmos-kit that can be used with Keplr and other wallets.
To broadcast messages, you can create signers with a variety of options:
Likely you'll want to use the Amino, so unless you need proto, you should use this one:
import { getOfflineSignerAmino as getOfflineSigner } from 'cosmjs-utils';
import { getOfflineSignerProto as getOfflineSigner } from 'cosmjs-utils';
WARNING: NOT RECOMMENDED TO USE PLAIN-TEXT MNEMONICS. Please take care of your security and use best practices such as AES encryption and/or methods from 12factor applications.
import { chains } from 'chain-registry';
const mnemonic =
  'unfold client turtle either pilot stock floor glow toward bullet car science';
  const chain = chains.find(({ chain_name }) => chain_name === 'agoric');
  const signer = await getOfflineSigner({
    mnemonic,
    chain
  });
Now that you have your stargateClient, you can broadcast messages:
const { send } = cosmos.bank.v1beta1.MessageComposer.withTypeUrl;
const msg = send({
    amount: [
    {
        denom: 'coin',
        amount: '1000'
    }
    ],
    toAddress: address,
    fromAddress: address
});
const fee: StdFee = {
    amount: [
    {
        denom: 'coin',
        amount: '864'
    }
    ],
    gas: '86364'
};
const response = await stargateClient.signAndBroadcast(address, [msg], fee);
If you want to manually construct a stargate client
import { OfflineSigner, GeneratedType, Registry } from "@cosmjs/proto-signing";
import { AminoTypes, SigningStargateClient } from "@cosmjs/stargate";
import { 
    cosmosAminoConverters,
    cosmosProtoRegistry,
    ibcProtoRegistry,
    ibcAminoConverters,
    agoricAminoConverters,
    agoricProtoRegistry
} from '@agoric/cosmic-proto';
const signer: OfflineSigner = /* create your signer (see above)  */
const rpcEndpint = 'https://rpc.cosmos.directory/agoric'; // or another URL
const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
    ...cosmosProtoRegistry,
    ...ibcProtoRegistry,
    ...agoricProtoRegistry
];
const aminoConverters = {
    ...cosmosAminoConverters,
    ...ibcAminoConverters,
    ...agoricAminoConverters
};
const registry = new Registry(protoRegistry);
const aminoTypes = new AminoTypes(aminoConverters);
const stargateClient = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
    registry,
    aminoTypes
});
When first cloning the repo:
yarn
yarn build
For very basic unit tests:
yarn test
To test with a real network,
yarn test:live
Protos live in ./proto. Look inside of scripts/codegen.cjs and configure the settings for bundling your SDK into @agoric/cosmic-proto:
yarn codegen
Build the types and then publish:
yarn build
yarn publish
Checkout these related projects: