eve-network
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

eve-network

TS library with Eve Cosmos SDK and Eve smart contracts.

npm install eve-network

Cosmos SDK clients

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' });
};

Cosmos Messages

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;

CosmWasm Messages

import { cosmwasm } from "stargaze-zone";

const {
    clearAdmin,
    executeContract,
    instantiateContract,
    migrateContract,
    storeCode,
    updateAdmin
} = cosmwasm.wasm.v1.MessageComposer.withTypeUrl;

IBC Messages

import { ibc } from 'eve-network';

const {
    transfer
} = ibc.applications.transfer.v1.MessageComposer.withTypeUrl

Connecting with Wallets and Signing Messages

⚡️ For web interfaces, we recommend using cosmos-kit. Continue below to see how to manually construct signers and clients.

Initializing the Stargate Client

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
});

Creating Signers

To broadcast messages, you'll want to use either keplr or an OfflineSigner from cosmjs using mnemonics.

Cosmos Kit

If you use react, for keplr, we recommend using cosmos-kit

Amino Signer

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';

Proto Signer

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
  });

Broadcasting messages

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);

Advanced Usage

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
});

Credits

🛠 Built by Cosmology — if you like our tools, please consider delegating to our validator ⚛️

Code built with the help of these related projects:

Readme

Keywords

none

Package Sidebar

Install

npm i eve-network

Weekly Downloads

1

Version

0.5.0

License

SEE LICENSE IN LICENSE

Unpacked Size

5.69 MB

Total Files

838

Last publish

Collaborators

  • pyramation