Socket
Socket
Sign inDemoInstall

evmosjs

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

evmosjs - npm Package Compare versions

Comparing version 0.3.2-rc3 to 0.3.2

dist/tests/network/broadcast.d.ts

15

dist/index.d.ts

@@ -1,7 +0,8 @@

import * as addressConverter from '@evmos/address-converter';
import * as eip712 from '@evmos/eip712';
import * as proto from '@evmos/proto';
import * as provider from '@evmos/provider';
import * as transactions from '@evmos/transactions';
export { addressConverter, eip712, proto, provider, transactions };
//# sourceMappingURL=index.d.ts.map
import * as addressConverter from '@evmos/address-converter'
import * as eip712 from '@evmos/eip712'
import * as proto from '@evmos/proto'
import * as provider from '@evmos/provider'
import * as transactions from '@evmos/transactions'
export { addressConverter, eip712, proto, provider, transactions }
// # sourceMappingURL=index.d.ts.map

@@ -1,7 +0,8 @@

import * as addressConverter from '@evmos/address-converter';
import * as eip712 from '@evmos/eip712';
import * as proto from '@evmos/proto';
import * as provider from '@evmos/provider';
import * as transactions from '@evmos/transactions';
export { addressConverter, eip712, proto, provider, transactions };
//# sourceMappingURL=index.js.map
import * as addressConverter from '@evmos/address-converter'
import * as eip712 from '@evmos/eip712'
import * as proto from '@evmos/proto'
import * as provider from '@evmos/provider'
import * as transactions from '@evmos/transactions'
export { addressConverter, eip712, proto, provider, transactions }
// # sourceMappingURL=index.js.map
{
"name": "evmosjs",
"description": "JS and TS libs for Evmos",
"version": "0.3.2-rc3",
"version": "0.3.2",
"license": "MIT",

@@ -31,6 +31,6 @@ "main": "dist/index.js",

"@evmos/address-converter": "^0.1.9",
"@evmos/eip712": "^0.3.1-rc1",
"@evmos/proto": "^0.2.1-rc1",
"@evmos/eip712": "^0.3.0",
"@evmos/proto": "^0.2.0",
"@evmos/provider": "^0.3.1",
"@evmos/transactions": "^0.3.0",
"@evmos/transactions": "^0.3.1",
"link-module-alias": "^1.2.0",

@@ -40,3 +40,10 @@ "shx": "^0.3.4"

"devDependencies": {
"@types/node": "^17.0.21"
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/keccak256": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/wallet": "^5.7.0",
"@types/node": "^17.0.21",
"node-fetch": "^3.3.0",
"secp256k1": "^5.0.0"
},

@@ -43,0 +50,0 @@ "publishConfig": {

@@ -1,309 +0,3 @@

# evmosjs
# Evmosjs
JS and TS libs for Evmos.
## Installation
evmosjs uses [buf.build](https://buf.build/) to manage [Evmos Protobuf dependencies](https://buf.build/evmos). To install evmosjs packages in your project,
follow the instructions corresponding to your package manager.
### NPM
Add the following line to an `.npmrc` file in your project root:
```ini
@buf:registry=https://buf.build/gen/npm/v1
```
Then run:
```bash
npm install evmosjs
```
Or:
```bash
npm install @evmos/[package]
```
### Yarn v2.x or v3.x
Add the following to an `.yarnrc.yml` file in your project root:
```yaml
npmScopes:
buf:
npmRegistryServer: "https://buf.build/gen/npm/v1"
```
Then run:
```bash
yarn add evmosjs
```
Or:
```bash
yarn add @evmos/[package]
```
Note that Yarn v1 is not supported ([see explanation](https://docs.buf.build/bsr/remote-packages/npm#other-package-managers)).
## Usage and Examples
### Query an Account
Query the account number, sequence, and pubkey for a given address.
```ts
import { generateEndpointAccount } from '@evmos/provider'
const address = 'evmos1...'
// Find node urls for either mainnet or testnet here:
// https://docs.evmos.org/develop/api/networks.
const nodeUrl = '...'
const queryEndpoint = `${nodeUrl}${generateEndpointAccount(address)}`
const restOptions = {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
}
// Note that the node will return a 400 status code if the account does not exist.
const rawResult = await fetch(
queryEndpoint,
restOptions,
)
const result = await rawResult.json()
// The response format is available at @evmos/provider/rest/account/AccountResponse.
// Note that the `pub_key` will be `null` if the address has not sent any transactions.
/*
account: {
'@type': string
base_account: {
address: string
pub_key?: {
'@type': string
key: string
}
account_number: string
sequence: string
}
code_hash: string
}
*/
```
### Create a Signable Transaction
Create a transaction payload which can be signed using either Metamask or Keplr.
This example uses `MsgSend`. View all signable transaction payloads in the [Transaction Docs](https://github.com/evmos/evmosjs/tree/main/docs/transactions).
```ts
import {
Chain,
Sender,
Fee,
TxContext,
MsgSendParams,
createTxMsgSend,
TxPayload,
} from '@evmos/transactions'
const chain: Chain = {
chainId: 9001,
cosmosChainId: 'evmos_9001-2',
}
// Populate the transaction sender parameters using the
// query API.
const sender: Sender = {
accountAddress: [sender_account_address],
sequence: [sender_sequence],
accountNumber: [sender_account_number],
// Use an empty string if the pubkey is unknown.
pubkey: [sender_pub_key],
}
const fee: Fee = {
amount: '4000000000000000',
denom: 'aevmos',
gas: '200000',
}
const memo = ''
const context: TxContext = {
chain,
sender,
fee,
memo,
}
const params: MsgSendParams = {
destinationAddress: [destination_address],
amount: [transaction_amount],
denom: 'aevmos',
}
const tx: TxPayload = createTxMsgSend(context, params)
```
### Sign the Transaction with MetaMask
Evmos supports EIP-712 signatures for Cosmos payloads to be signed using Ethereum wallets such as MetaMask.
```ts
import { createTxRaw } from '@evmos/proto'
import { evmosToEth } from '@evmos/address-converter'
// First, populate a TxContext object and create a signable Tx payload.
// (See 'Create a Signable Transaction' to learn how to create these).
const context = ...
const tx = ...
const { sender } = context
// Initialize MetaMask and sign the EIP-712 payload.
await window.ethereum.enable()
const senderHexAddress = evmosToEth(sender.accountAddress)
const eip712Payload = JSON.stringify(tx.eipToSign)
const signature = await window.ethereum.request({
method: 'eth_signTypedData_v4',
params: [senderHexAddress, eip712Payload],
})
// Create a signed Tx payload that can be broadcast to a node.
const signatureBytes = Buffer.from(signature.replace('0x', ''), 'hex')
const { signDirect } = tx
const bodyBytes = signDirect.body.toBinary()
const authInfoBytes = signDirect.authInfo.toBinary()
const signedTx = createTxRaw(
bodyBytes,
authInfoBytes,
[signatureBytes],
)
```
### Sign the Transaction with Keplr (SignDirect)
EvmosJS supports Cosmos SDK `SignDirect` payloads that can be signed using Keplr.
```ts
import { createTxRaw } from '@evmos/proto'
// First, populate a TxContext object and create a signable Tx payload.
// (See 'Create a Signable Transaction' to learn how to create these).
const context = ...
const tx = ...
const { chain, sender } = context
const { signDirect } = tx
const signResponse = await window?.keplr?.signDirect(
chain.cosmosChainId,
sender.accountAddress,
{
bodyBytes: signDirect.body.toBinary(),
authInfoBytes: signDirect.authInfo.toBinary(),
chainId: chain.cosmosChainId,
accountNumber: new Long(sender.accountNumber),
},
)
if (!signResponse) {
// Handle signature failure here.
}
const signatures = [
new Uint8Array(Buffer.from(signResponse.signature.signature, 'base64')),
]
const { signed } = signResponse
const signedTx = createTxRaw(
signed.bodyBytes,
signed.authInfoBytes,
signatures,
)
```
### Sign the Transaction with Keplr (EIP-712)
EvmosJS also supports signing [EIP-712](https://eips.ethereum.org/EIPS/eip-712) payloads using Keplr. This is necessary for Ledger users on Keplr, since the Ledger device cannot sign `SignDirect` payloads.
```ts
import { EthSignType } from '@keplr-wallet/types';
import { createTxRaw } from '@evmos/proto'
// First, populate a TxContext object and create a signable Tx payload.
// (See 'Create a Signable Transaction' to learn how to create these).
const context = ...
const tx = ...
const { chain, sender } = context
const eip712Payload = JSON.stringify(tx.eipToSign)
const signature = await window?.keplr?.signEthereum(
chain.cosmosChainId,
sender.accountAddress,
eip712Payload,
EthSignType.EIP712,
)
if (!signature) {
// Handle signature failure here.
}
const { signDirect } = tx
const bodyBytes = signDirect.body.toBinary()
const authInfoBytes = signDirect.authInfo.toBinary()
const signedTx = createTxRaw(
bodyBytes,
authInfoBytes,
[signature],
)
```
### Broadcast the Signed Transaction
Regardless of how the transaction is signed, broadcasting takes place the same way.
```ts
import {
generateEndpointBroadcast,
generatePostBodyBroadcast,
} from '@evmos/provider'
// First, sign a transaction using MetaMask or Keplr.
const signedTx = createTxRaw(...)
// Find a node URL from a network endpoint:
// https://docs.evmos.org/develop/api/networks.
const nodeUrl = ...
const postOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: generatePostBodyBroadcast(signedTx),
}
const broadcastEndpoint = `${nodeUrl}${generateEndpointBroadcast()}`
const broadcastPost = await fetch(
broadcastEndpoint,
postOptions,
)
const response = await broadcastPost.json()
```
Main package
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc