Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
injectivejs
Advanced tools
Readme
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 rpcEndpoint = '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
injective
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 2 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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).