joshstevens19 / simple-pancakeswap-sdk Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hello, is it possibile with this lib to make a swap using our own Contract to get fees?
I mean actually we are using just web3.js and do something like that
const contract = new this.web3.eth.Contract(abi, '0x0........80');
contract.methods.swap..........
How can we replicate this?
thx
@joshstevens19
code:
const p = new PancakeswapPair({
// the contract address of the token you want to convert FROM
fromTokenContractAddress: '0x55d398326f99059ff775485246999027b3197955',
// the contract address of the token you want to convert TO
toTokenContractAddress: '0xf16e81dce15B08F326220742020379B855B87DF9',
// the ethereum address of the user using this part of the dApp
ethereumAddress: 'my wallet address',
// you can pass in the provider url as well if you want
// providerUrl: YOUR_PROVIDER_URL,
settings: new PancakeswapPairSettings({
// if not supplied it will use `0.005` which is 0.5%
// please pass it in as a full number decimal so 0.7%
// would be 0.007
slippage: 0.01,
// if not supplied it will use 20 a deadline minutes
deadlineMinutes: 20,
// if not supplied it will try to use multihops
// if this is true it will require swaps to direct
// pairs
disableMultihops: false,
}),
});
const pancakeswapPairFactory = await p.createFactory();
const trade = await pancakeswapPairFactory.trade('10');
exception:
Error: call revert exception (method="aggregate((address,bytes)[])", errorArgs=["Multicall aggregate: call failed"], errorName="Error", errorSignature="Error(string)", reason="Multicall aggregate: call failed", code=CALL_EXCEPTION, version=abi/5.4.0)
at Logger.makeError (/path/node_modules/@ethersproject/logger/lib/index.js:187:21)
at Logger.throwError (/path/node_modules/@ethersproject/logger/lib/index.js:196:20)
at Interface.decodeFunctionResult (/path/node_modules/@ethersproject/abi/lib/interface.js:384:23)
at Object.<anonymous> (/path/node_modules/@ethersproject/contracts/lib/index.js:338:56)
at step (/path/node_modules/@ethersproject/contracts/lib/index.js:48:23)
at Object.next (/path/node_modules/@ethersproject/contracts/lib/index.js:29:53)
at fulfilled (/path/node_modules/@ethersproject/contracts/lib/index.js:20:58)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
reason: 'Multicall aggregate: call failed',
code: 'CALL_EXCEPTION',
method: 'aggregate((address,bytes)[])',
errorArgs: [ 'Multicall aggregate: call failed' ],
errorName: 'Error',
errorSignature: 'Error(string)',
address: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D',
args: [ [ [Object], [Object], [Object], [Object], [Object] ] ],
transaction: {
data: '0x252dba420000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000004a0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c4d06ca61f0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000300000000000000000000000055d398326f99059ff775485246999027b3197955000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000f16e81dce15b08f326220742020379b855b87df90000000000000000000000000000000000000000000000000000000000000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e4d06ca61f0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000400000000000000000000000055d398326f99059ff775485246999027b31979550000000000000000000000008ac76a51cc950d9822d68b83fe1ad97b32cd580d000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000f16e81dce15b08f326220742020379b855b87df90000000000000000000000000000000000000000000000000000000000000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e4d06ca61f0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000400000000000000000000000055d398326f99059ff775485246999027b319795500000000000000000000000026a5dfab467d4f58fb266648cae769503cec9580000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000f16e81dce15b08f326220742020379b855b87df90000000000000000000000000000000000000000000000000000000000000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e4d06ca61f0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000400000000000000000000000055d398326f99059ff775485246999027b319795500000000000000000000000026a5dfab467d4f58fb266648cae769503cec9580000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000f16e81dce15b08f326220742020379b855b87df90000000000000000000000000000000000000000000000000000000000000000000000000000000010ed43c718714eb63d5aa57b78b54704e256024e000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e4d06ca61f0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000400000000000000000000000055d398326f99059ff775485246999027b31979550000000000000000000000008ac76a51cc950d9822d68b83fe1ad97b32cd580d000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000f16e81dce15b08f326220742020379b855b87df900000000000000000000000000000000000000000000000000000000',
to: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D'
}
}
How can I fix it?
simple-uniswap-sdk
has support for TradeDirection, to request quotes for desired input & output amounts. Can this be added to to simple-pancakeswap-sdk
?
const pancakeswapPair = new PancakeswapPair({
// the contract address of the token you want to convert FROM
fromTokenContractAddress: fromTokenContractAddress,
// the contract address of the token you want to convert TO
toTokenContractAddress: toTokenContractAddress,
// the ethereum address of the user using this part of the dApp
ethereumAddress: ethereumAddress,
});
// now to create the factory you just do
const pancakeswapPairFactory = await pancakeswapPair.createFactory();
// const trade = await pancakeswapPairFactory.findBestRoute('10');
const trade = await pancakeswapPairFactory.trade('10');
I was trying to use pancakeSwapPairFactory.trade(tokenAmount);
but noticed it threw out of bounds error.
Upon further tests, it seems the error was from findBestRound
.
I've tested this with mainnet tokens and it worked fine.
const RPC_URL = "https://data-seed-prebsc-1-s1.binance.org:8545/";
const pancakeswapPair = new PancakeswapPair({
// the contract address of the token you want to convert FROM
fromTokenContractAddress: tokenFrom.address,
//fromTokenContractAddress: WBNB.token().contractAddress,
// the contract address of the token you want to convert TO
toTokenContractAddress: tokenTo.address,
// the ethereum address of the user using this part of the dApp
ethereumAddress: "0x6aA9d7DB4035cA7BbacB48fe00095a619231b1fC",
providerUrl: RPC_URL,
});
const bestRoute = await pancakeSwapPairFactory.findBestRoute("10");
console.log(bestRoute);
Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.5.0)
at Logger.makeError (index.js:185:1)
at Logger.throwError (index.js:194:1)
at Reader._peekBytes (abstract-coder.js:126:1)
at Reader.readBytes (abstract-coder.js:138:1)
at Reader.readValue (abstract-coder.js:144:1)
at AddressCoder.decode (address.js:22:1)
at array.js:91:1
at Array.forEach (<anonymous>)
at unpack (array.js:70:1)
at TupleCoder.decode (tuple.js:54:1)
at AbiCoder.decode (abi-coder.js:93:1)
at Multicall.<anonymous> (multicall.js:184:1)
at step (multicall.js:32:1)
at Object.next (multicall.js:13:1)
at fulfilled (multicall.js:4:1)
This package is so close to the regular Simple-Uniswap-SDK, I am wondering what is so different for there to be two different packages. With the Uniswap one we can enter custom networks to support BSC and pancake. Wouldn't it be better to make a Simple-Dex-SDK and support both? That way we can use predefined network easier. For example, I am having a hell of a time in simple Uniswap to get the native BNB coin as a trade, when in this package they have BNB setup like ETH and can easily call the native tokens contract to trade.
const pancakeswapPair = new PancakeswapPair({
fromTokenContractAddress: '0x8519ea49c997f50ceffa444d240fb655e89248aa',
toTokenContractAddress: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
ethereumAddress: '0xB1E6079212888f0bE0cf55874B2EB9d7a5e02cD9',
});
const pancakeswapPairFactory = await pancakeswapPair.createFactory();
const bestRoute = await pancakeswapPairFactory.findBestRoute('10')
console.log(bestRoute);
First off, thank for your work on this. Really helps me with what I'm doing.
I'm getting this error when I try to find the best route. It works on other tokens but not on this one or Safemoon for example:
Error: call revert exception (method="aggregate((address,bytes)[])", errorArgs=["Multicall aggregate: call failed"], errorName="Error", errorSignature="Error(string)", reason="Multicall aggregate: call failed", code=CALL_EXCEPTION, version=abi/5.4.0)
at Logger.makeError (index.ts:213)
at Logger.throwError (index.ts:225)
at Interface.decodeFunctionResult (interface.ts:425)
at Object. (index.ts:332)
at Generator.next ()
at fulfilled (index.ts:2)
I am importing TradeContext from require statement like this:
const { TradeContext } = require("simple-pancakeswap-sdk");
But NodeJs is unable to read all the interfaces exported by index.d.ts and reading classes perfectly, how to import interfaces in my code?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.