全部版块 我的主页
论坛 数据科学与人工智能 人工智能 智能设备与机器人
626 0
2022-06-21

狩猎者Hunter项目小助手系统开发需要用到 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);

});


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群