npm install --save @archwayhq/arch3-proto
yarn add @archwayhq/arch3-proto
-
./scripts/codegen.js
is the core file that does the codegen work - the path to proto files is set in
protoDirs
- note as the proto files change the codeGenRunner configs may need to change for a correct gen to happen
- note any imports of a proto file MUST be included into the package's
proto
folder- for example,
./proto/archway/rewards/v1beta1/events.proto
does an import ofgogoproto/gogo.proto
, so this file was added intoproto/gogoproto/gogo.proto
- use the
<workspace-root>/scripts/import-proto.sh
script to get both the protocol's protos and their dependencies
- for example,
-
codegen
generate the ts codegen files in the./generated
folder -
build
can then be run after to compile the Typescript files
- When testing you must first have the generated code, use
yarn code
andyarn build
.
import { archway } from '@archwayhq/arch3-proto' ;
const { createRPCQueryClient } = archway.ClientFactory;
const client = await createRPCQueryClient({ rpcEndpoint: RPC_ENDPOINT });
// now you can query the cosmos modules
const balance = await client.cosmos.bank.v1beta1
.allBalances({ address: 'archway1addresshere' });
// you can also query the archway modules
const balances = await client.archway.exchange.v1beta1
.exchangeBalances()
Import the archway
object from arch3-proto
.
import { archway } from '@archwayhq/arch3-proto' ;
const {
createSpotLimitOrder,
createSpotMarketOrder,
deposit
} = archway.exchange.v1beta1.MessageComposer.withTypeUrl;
import { cosmwasm } from '@archwayhq/arch3-proto';
const {
clearAdmin,
executeContract,
instantiateContract,
migrateContract,
storeCode,
updateAdmin
} = cosmwasm.wasm.v1.MessageComposer.withTypeUrl;
import { ibc } from '@archwayhq/arch3-proto' ;
const {
transfer
} = ibc.applications.transfer.v1.MessageComposer.withTypeUrl
import { cosmos } from '@archwayhq/arch3-proto' ;
const {
fundCommunityPool,
setWithdrawAddress,
withdrawDelegatorReward,
withdrawValidatorCommission
} = cosmos.distribution.v1beta1.MessageComposer.fromPartial;
const {
multiSend,
send
} = cosmos.bank.v1beta1.MessageComposer.fromPartial;
const {
beginRedelegate,
createValidator,
delegate,
editValidator,
undelegate
} = cosmos.staking.v1beta1.MessageComposer.fromPartial;
const {
deposit,
submitProposal,
vote,
voteWeighted
} = cosmos.gov.v1beta1.MessageComposer.fromPartial;
Use getSigningarchwayClient
to get your SigningStargateClient
, with the proto/amino messages full-loaded. No need to manually add amino types, just require and initialize the client:
import { getSigningarchwayClient } from '@archwayhq/arch3-proto' ;
const stargateClient = await getSigningarchwayClient({
rpcEndpoint,
signer // OfflineSigner
});
To broadcast messages, you can create signers with a variety of options:
import { getOfflineSignerProto as getOfflineSigner } from 'cosmjs-utils';
:warn: DO NOT 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 === 'archway');
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 response = await stargateClient.signAndBroadcast(address, [msg], 'auto');
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,
cosmwasmAminoConverters,
cosmwasmProtoRegistry,
ibcProtoRegistry,
ibcAminoConverters,
archwayAminoConverters,
archwayProtoRegistry
} from '@archwayhq/arch3-proto' ;
const signer: OfflineSigner = /* create your signer (see above) */
const rpcEndpint = 'https://rpc.cosmos.directory/archway'; // or another URL
const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
...cosmosProtoRegistry,
...cosmwasmProtoRegistry,
...ibcProtoRegistry,
...archwayProtoRegistry
];
const aminoConverters = {
...cosmosAminoConverters,
...cosmwasmAminoConverters,
...ibcAminoConverters,
...archwayAminoConverters
};
const registry = new Registry(protoRegistry);
const aminoTypes = new AminoTypes(aminoConverters);
const stargateClient = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
registry,
aminoTypes
});
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.