
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
injectivejs
Advanced tools
Building the future of decentralized exchange
npm install injectivejs
import { contracts } from 'injectivejs';
const { RegistryClient } = contracts.Registry;
const client = new RegistryClient(
signingCosmWasmClient, // make sure to create your client (see docs below)
senderAddress,
contractAddress
);
await client.activate({
contractAddress
})
const activeContracts = await client.getActiveContracts();
const {
address,
gas_limit,
gas_price,
is_executable
} = activeContracts.contracts[0];
import { injective } from 'injectivejs';
const { createRPCQueryClient } = injective.ClientFactory;
const client = await createRPCQueryClient({ rpcEndpoint: RPC_ENDPOINT });
// now you can query the cosmos modules
const balance = await client.cosmos.bank.v1beta1
.allBalances({ address: 'inj1addresshere' });
// you can also query the injective modules
const balances = await client.injective.exchange.v1beta1
.exchangeBalances()
Import the injective
object from injectivejs
.
import { injective } from 'injectivejs';
const {
createSpotLimitOrder,
createSpotMarketOrder,
deposit
} = injective.exchange.v1beta1.MessageComposer.withTypeUrl;
const {
bid
} = injective.auction.v1beta1.MessageComposer.withTypeUrl;
const {
adminUpdateBinaryOptionsMarket,
batchCancelBinaryOptionsOrders,
batchCancelDerivativeOrders,
batchCancelSpotOrders,
batchCreateDerivativeLimitOrders,
batchCreateSpotLimitOrders,
batchUpdateOrders,
cancelBinaryOptionsOrder,
cancelDerivativeOrder,
cancelSpotOrder,
createBinaryOptionsLimitOrder,
createBinaryOptionsMarketOrder,
createDerivativeLimitOrder,
createDerivativeMarketOrder,
createSpotLimitOrder,
createSpotMarketOrder,
deposit,
exec,
externalTransfer,
increasePositionMargin,
instantBinaryOptionsMarketLaunch,
instantExpiryFuturesMarketLaunch,
instantPerpetualMarketLaunch,
instantSpotMarketLaunch,
liquidatePosition,
rewardsOptOut,
subaccountTransfer,
withdraw
} = injective.exchange.v1beta1.MessageComposer.withTypeUrl;
const {
createInsuranceFund,
requestRedemption,
underwrite
} = injective.insurance.v1beta1.MessageComposer.withTypeUrl;
const {
acceptPayeeship,
createFeed,
fundFeedRewardPool,
setPayees,
transferPayeeship,
transmit,
updateFeed,
withdrawFeedRewardPool
} = injective.ocr.v1beta1.MessageComposer.withTypeUrl;
const {
relayBandRates,
relayCoinbaseMessages,
relayPriceFeedPrice,
relayProviderPrices,
requestBandIBCRates
} = injective.oracle.v1beta1.MessageComposer.withTypeUrl;
const {
cancelSendToEth,
confirmBatch,
depositClaim,
eRC20DeployedClaim,
requestBatch,
sendToEth,
setOrchestratorAddresses,
submitBadSignatureEvidence,
valsetConfirm,
valsetUpdateClaim,
withdrawClaim
} = injective.peggy.v1.MessageComposer.withTypeUrl;
import { cosmwasm } from "injectivejs";
const {
clearAdmin,
executeContract,
instantiateContract,
migrateContract,
storeCode,
updateAdmin
} = cosmwasm.wasm.v1.MessageComposer.withTypeUrl;
import { ibc } from 'injectivejs';
const {
transfer
} = ibc.applications.transfer.v1.MessageComposer.withTypeUrl
import { cosmos } from 'injectivejs';
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;
⚡️ 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.
Use getSigningInjectiveClient
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 { getSigningInjectiveClient } from 'injectivejs';
const stargateClient = await getSigningInjectiveClient({
rpcEndpoint,
signer // OfflineSigner
});
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 === 'injective');
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: 'inj',
amount: '1000'
}
],
toAddress: address,
fromAddress: address
});
const fee: StdFee = {
amount: [
{
denom: 'inj',
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,
injectiveAminoConverters,
injectiveProtoRegistry
} from 'injectivejs';
const signer: OfflineSigner = /* create your signer (see above) */
const rpcEndpint = 'https://rpc.cosmos.directory/injective'; // or another URL
const protoRegistry: ReadonlyArray<[string, GeneratedType]> = [
...cosmosProtoRegistry,
...cosmwasmProtoRegistry,
...ibcProtoRegistry,
...injectiveProtoRegistry
];
const aminoConverters = {
...cosmosAminoConverters,
...cosmwasmAminoConverters,
...ibcAminoConverters,
...injectiveAminoConverters
};
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
Contract schemas live in ./contracts
, and protos in ./proto
. Look inside of scripts/codegen.js
and configure the settings for bundling your SDK and contracts into injectivejs
:
yarn codegen
Build the types and then publish:
yarn build:ts
yarn publish
🛠 Built by Cosmology — if you like our tools, please consider delegating to our validator ⚛️
Code built with the help of these related projects:
FAQs
Injectivejs is a JavaScript library for interacting with injective sdk.
The npm package injectivejs receives a total of 463 weekly downloads. As such, injectivejs popularity was classified as not popular.
We found that injectivejs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.