狩猎者Hunter项目小助手系统开发代码分享

2022-06-21 15:20:22 浏览数 (1)

需要用到 ethers 这个库

直接上代码 const ethers = require('ethers');

const addresses = {

WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",

router: "0x10ED43C718714eb63d5aA57B78B54704E256024E",

factory: "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",

me: "YOUR_WALLET_ADDRESS"

}

const provider = new ethers.providers.WebSocketProvider("wss://bsc-ws-node.nariox.org:443");

let privateKey = `你的钱包私钥`;

const wallet = new ethers.Wallet(privateKey);

const account = wallet.connect(provider);

const factory = new ethers.Contract(

addresses.factory,

['event PairCreated(address indexed token0, address indexed token1, address pair, uint)'],

account,

);

const router = new ethers.Contract(

addresses.router,

[

'function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts)',

'function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)',

],

account,

);

factory.on("PairCreated", async (token0, token1, addressPair) => {

console.log('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

console.log('token0', token0);

console.log('token1', token1);

console.log('addressPair', addressPair);

});

0 人点赞