Comparing version 4.6.0 to 4.6.1
@@ -6,2 +6,3 @@ export declare const networks: { | ||
}; | ||
export declare const DEPRECATED_NETWORK_IDS: number[]; | ||
export declare const DEFAULT_RATE_LIMIT_RULES: { | ||
@@ -8,0 +9,0 @@ points: number; |
@@ -1,4 +0,4 @@ | ||
import { SimulationTransaction, SimulationTransactionOutput } from './types'; | ||
import { SimulationTransaction, MultiSimOutput } from './types'; | ||
import SDK from '.'; | ||
declare function multiSim(this: SDK, transactions: SimulationTransaction[]): Promise<SimulationTransactionOutput[]>; | ||
declare function multiSim(this: SDK, transactions: SimulationTransaction[]): Promise<MultiSimOutput>; | ||
export default multiSim; |
import { Subject } from 'rxjs'; | ||
import { SimulationTransactionOutput } from './types'; | ||
import { MultiSimOutput, SimulationTransactionOutput } from './types'; | ||
export declare const simulations$: Subject<{ | ||
eventId: string; | ||
transaction: SimulationTransactionOutput | SimulationTransactionOutput[]; | ||
transaction: SimulationTransactionOutput | MultiSimOutput; | ||
}>; |
@@ -1,2 +0,2 @@ | ||
import { Subject } from 'rxjs'; | ||
import type { Subject } from 'rxjs'; | ||
export interface NotificationObject { | ||
@@ -14,3 +14,3 @@ type?: 'pending' | 'success' | 'error' | 'hint'; | ||
params: Record<string, unknown>; | ||
contractName: string; | ||
contractName?: string; | ||
contractDecimals?: number; | ||
@@ -50,3 +50,3 @@ decimalValue?: string; | ||
gas: number; | ||
gasPrice: string; | ||
gasPrice?: string; | ||
gasUsed?: string; | ||
@@ -104,4 +104,4 @@ input: string; | ||
} | ||
export declare type System = 'bitcoin' | 'ethereum'; | ||
export declare type Network = 'main' | 'testnet' | 'ropsten' | 'rinkeby' | 'goerli' | 'kovan' | 'xdai' | 'bsc-main' | 'matic-main' | 'fantom-main' | 'matic-mumbai' | 'local'; | ||
export declare type System = 'ethereum'; | ||
export declare type Network = 'main' | 'ropsten' | 'rinkeby' | 'goerli' | 'xdai' | 'matic-main' | 'matic-mumbai' | 'local'; | ||
export declare type Status = 'pending' | 'confirmed' | 'speedup' | 'cancel' | 'failed' | 'dropped' | 'simulated'; | ||
@@ -249,3 +249,3 @@ export interface InputOutput { | ||
type: number; | ||
gasUsed: string; | ||
gasUsed: number; | ||
internalTransactions?: InternalTransaction[]; | ||
@@ -262,2 +262,17 @@ netBalanceChanges?: BalanceChange[]; | ||
} | ||
export declare type MultiSimOutput = { | ||
id?: string; | ||
contractCall: ContractCall[]; | ||
error?: any; | ||
gasUsed: number[]; | ||
internalTransactions: InternalTransaction[][]; | ||
netBalanceChanges: NetBalanceChange[][]; | ||
network: Network; | ||
simDetails: SimDetails; | ||
serverVersion: string; | ||
system: System; | ||
status: Status; | ||
simulatedBlockNumber: number; | ||
transactions: InternalTransaction[]; | ||
}; | ||
export interface Simulate { | ||
@@ -322,3 +337,3 @@ (system: System, network: Network, transaction: SimulationTransaction): Promise<SimulationTransactionOutput>; | ||
emitter?: Emitter; | ||
subscription?: Subject<string>; | ||
subscription?: Subject<void>; | ||
} | ||
@@ -325,0 +340,0 @@ export interface Transaction { |
{ | ||
"name": "bnc-sdk", | ||
"version": "4.6.0", | ||
"version": "4.6.1", | ||
"description": "SDK to connect to the blocknative backend via a websocket connection", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
116
README.md
@@ -137,2 +137,118 @@ # Blocknative sdk | ||
#### Transaction Preview | ||
#### Overview | ||
Transaction Preview lets you preview the outputs of any custom transactions that you submit to it. By harnessing the power of our network of Ethereum nodes, with our existing decoding and transaction lifecycle knowledge, we hope to give users of Transaction Preview even greater comfort when interacting in the Web3 space. Previewing a transaction is particularly useful for: | ||
Wallets: Help users preview net-balance changes & identify malicious contract behavior or buggy smart contracts before interacting with them. | ||
DEXs & Swaps: Report accurate slippage, Accurate tokens received, and accurate failing calls | ||
Traders: Preview many iterations of the same trade and execute only the most profitable one | ||
Lending Protocols: Tell whether a Borrow / Repay / Claim transaction will go through | ||
Auctions: Tell whether your bid or listing will go through and its accuracy & effects | ||
NFTs: Tell whether your NFT mint, purchase, or transfer will go through | ||
& much more without spending a single wei in gas! | ||
#### Supported Networks | ||
Transaction Preview is currently only supported for **Ethereum: Main**. Please stay tuned for its availability on other networks supported by Blocknative. | ||
#### Rate Limits | ||
Usage rate limit for the Transaction Preview API is 100 requests per 60-second window. Transaction Preview consumes the same daily limits on your Blocknative plan as pending simulated transactions in Simulation Platform. You can view your current consumption on your Blocknative Account Page. | ||
#### Usage | ||
This example will mock a contract interaction between two wallets. | ||
```typescript | ||
import BlocknativeSdk, { SimulationTransaction, MultiSimOutput } from 'bnc-sdk' | ||
import { SimulationTransaction, MultiSimOutput } from 'bnc-sdk' | ||
import { ethers } from 'ethers' | ||
const addressFrom = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' | ||
const CONTRACT_ADDRESS = '0x7a250d5630b4cf539739df2c5dacb4c659f2488d' | ||
const erc20_interface = [ | ||
'function approve(address _spender, uint256 _value) public returns (bool success)', | ||
'function transferFrom(address sender, address recipient, uint256 amount) external returns (bool)', | ||
'function balanceOf(address owner) view returns (uint256)' | ||
] | ||
const uniswapV2router_interface = [ | ||
'function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)' | ||
] | ||
const weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' | ||
const dai = '0x6B175474E89094C44Da98b954EedeAC495271d0F' | ||
let swapTxData | ||
let approveTxData | ||
const createTransaction = async () => { | ||
const swapContract = new ethers.Contract( | ||
CONTRACT_ADDRESS, | ||
uniswapV2router_interface | ||
) | ||
const erc20_contract = new ethers.Contract(weth, erc20_interface) | ||
const oneEther = ethers.BigNumber.from('1591000000000000000000') | ||
approveTxData = await erc20_contract.populateTransaction.approve( | ||
CONTRACT_ADDRESS, | ||
oneEther | ||
) | ||
const amountOutMin = 0 | ||
const amountOutMinHex = ethers.BigNumber.from(amountOutMin.toString())._hex | ||
const path = [dai, weth] | ||
const deadline = Math.floor(Date.now() / 1000) + 60 * 1 // 1 minutes from the current Unix time | ||
const inputAmountHex = oneEther.toHexString() | ||
swapTxData = await swapContract.populateTransaction.swapExactTokensForETH( | ||
inputAmountHex, | ||
amountOutMinHex, | ||
path, | ||
addressFrom, | ||
deadline | ||
) | ||
} | ||
await createTransaction() | ||
const account_address = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' | ||
const uniswapV2Router = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D' | ||
const stubTrans = [ | ||
{ | ||
from: account_address, | ||
to: dai, | ||
input: approveTxData.data, | ||
gas: 1000000, | ||
gasPrice: 48000000000, | ||
value: 0 | ||
}, | ||
{ | ||
from: account_address, | ||
to: uniswapV2Router, | ||
input: swapTxData.data, | ||
gas: 1000000, | ||
gasPrice: 48000000000, | ||
value: 0 | ||
} | ||
] | ||
// create options object | ||
const options = { | ||
dappId: '<YOUR_API_KEY>', | ||
networkId: 1 | ||
} | ||
// initialize and connect to the api | ||
const blocknativeSDK = new BlocknativeSdk(options) | ||
const singleSim: Promise<SimulationTransactionOutput> = blocknativeSDK.simulate( | ||
'ethereum', | ||
'main', | ||
stubTrans[1] | ||
) | ||
const multiSim: Promise<MultiSimOutput> = blocknativeSDK.multiSim(stubTrans) | ||
``` | ||
#### Address Listener | ||
@@ -139,0 +255,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
659130
332
20191