前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >狩猎者Hunter项目小助手系统开发代码分享

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

原创
作者头像
KFZ433
发布2022-06-21 15:20:22
3350
发布2022-06-21 15:20:22
举报
文章被收录于专栏:NFT链游的应用NFT链游的应用

需要用到 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);

});

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档