TS library with Eve Cosmos SDK and Eve smart contracts.
npm install eve-network
import { eve } from 'eve-network';
const main = async () => {
const { createLCDClient } = eve.ClientFactory;
const client = await createLCDClient({ restEndpoint: REST_ENDPOINT });
// now you can query the modules
const balance = await client.cosmos.bank.v1beta1
.allBalances({ address: 'eve1addresshere' });
};
import { cosmos } from 'eve-network';
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;
import { cosmwasm } from "stargaze-zone";
const {
clearAdmin,
executeContract,
instantiateContract,
migrateContract,
storeCode,
updateAdmin
} = cosmwasm.wasm.v1.MessageComposer.withTypeUrl;
import { ibc } from 'eve-network';
const {
transfer
} = ibc.applications.transfer.v1.MessageComposer.withTypeUrl
⚡️ For web interfaces, we recommend using cosmos-kit. Continue below to see how to manually construct signers and clients.
Use getSigningEveClient
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 { getSigningEveClient } from 'eve-network';
const stargateClient = await getSigningEveClient({
rpcEndpoint,
signer // OfflineSigner
});
To broadcast messages, you'll want to use either keplr or an OfflineSigner
from cosmjs
using mnemonics.
If you use react, for keplr, we recommend using cosmos-kit
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 === 'eve');
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: 'ueve',
amount: '1000'
}
],
toAddress: address,
fromAddress: address
});
const fee: StdFee = {
amount: [
{
denom: 'ueve',
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,
cosmwasmAminoConverters,
cosmwasmProtoRegistry,
ibcProtoRegistry,
ibcAminoConverters,
eveAminoConverters,
eveProtoRegistry
} from 'eve-network';
const signer: OfflineSigner = /* create your signer (see above) */
const rpcEndpint = 'https://rpc.cosmos.directory/eve'; // or another URL
const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
...cosmosProtoRegistry,
...eveProtoRegistry,
...cosmwasmProtoRegistry,
...ibcProtoRegistry
];
const aminoConverters = {
...cosmosAminoConverters,
...eveAminoConverters,
...cosmwasmAminoConverters,
...ibcAminoConverters
};
const registry = new Registry(protoRegistry);
const aminoTypes = new AminoTypes(aminoConverters);
const stargateClient = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
registry,
aminoTypes
});
🛠 Built by Cosmology — if you like our tools, please consider delegating to our validator ⚛️
Code built with the help of these related projects:
- @cosmwasm/ts-codegen for generated CosmWasm contract Typescript classes
- @cosmology/telescope a "babel for the Cosmos", Telescope is a TypeScript Transpiler for Cosmos Protobufs.