scorpion9979
  • Member for 2 years, 10 months
  • Last seen this week
Is there any way to upload to IPFS or Swarm from inside a smart contract?
5 votes

The Ethereum blockchain is an entirely separate system from IPFS, it does not understand what IPFS is or what it does. In most DApps, what usually happens is that the file is uploaded to IPFS via the ...

View answer
Detect if destination is a Uniswap V3 Pool
5 votes

The easiest implementation would be to simply check for the destination contract's factory parameter, since the single common denominator of all Uniswap V3 pools is that they all have the same Uniswap ...

View answer
how to deploy a smart contract on same address in ethereum and binance
4 votes

If your deployment environment employs the CREATE opcode under the hood, The deployed contract address is going to be a function of the deployer's EOA and the nonce. contractAddress = hash(...

View answer
etherjs equivalent of abi.encodeWithSignature
3 votes

It would something along the lines of: let ABI = [signature]; let iface = new ethers.utils.Interface(ABI); iface.encodeFunctionData(functionName, [param1, param2, ...]); Note that signature needs to ...

View answer
How to set private key for Ethers Signer
Accepted answer
3 votes

You could simply replace the 2nd line in your code above and instead define the signer as follows: const signer = new ethers.Wallet(your_private_key_string, provider); You could also define a signer ...

View answer
What do you as parameters to external functions in solidity that take struct as parameters?
3 votes

You would just use a JSON format for that param. In web3js, the method would accept a JSON object as follows: contract.decreaseLiquidity({ tokenId: 12345, liquidity: 100, amount0Min: 100, amount1Min: ...

View answer
How do you estimate the gas cost to deploy a smart contract with Ethers.js?
Accepted answer
2 votes

You'll first need to get the encoded contract deployment data as follows: const deploymentData = contract.interface.encodeDeploy([<constructor_arguments>]) Then, you could use the data to get ...

View answer
How can I reference a deployed library in my solidity contract
Accepted answer
2 votes

I think you could use web3 to link the contract to be deployed to the library that is already deployed, as the following StackExchange answer suggests. code: const ConvertLib = artifacts.require("...

View answer
How to store unlimited array of 10 numbers mapped to address?
2 votes

Ok, so the error message is quite clear: Internal or recursive type is not allowed for public state variables In your case, the problem is that you're using recursive types for the numbers public ...

View answer
How to get the ERC-20 token balance of an account using etherjs?
Accepted answer
2 votes

You could do the following: const ethers = require('ethers'); const genericErc20Abi = require(..../.../Erc20.json); const tokenContractAddress = '0x...'; const provider = ...; (use ethers.providers....

View answer
Why does smart contract successfully deploying to Rinkeby fail to deploy to mainnet?
Accepted answer
2 votes

You need to re-calculate the amount of ETH you need for the mainnet deployment as follows: deploymentCostInETH = gasAmount * gasPrice deploymentCostInETH differs depending on the current gas price. ...

View answer
food delivery dapp: handling driver sort algorithm over smart contract?
2 votes

It could be practical if you launch it on an L2 (I would suggest Matic, since it has most of the users). You could use Chainlink's VRF for randomizing the driver assignment (driver data would be ...

View answer
Chainlink Beginner Tutorial: call to PriceConsumerV3.getLatestPrice errored: [object Object]
2 votes

This appears to be a Remix-specific error. I copied what you did, deployed it on Kovan via Remix, and got the same error. Then, I tried to use the Etherscan interface to read that data after verifying ...

View answer
Web3: Get token address from pair address
2 votes

You get the tokens that make up the trading pair by calling following lines on the pair contract: token0 = contract.functions.token0().call() token1 = contract.functions.token1().call() I used the ...

View answer
Using SafeMath with older Solidity compiler
2 votes

Solidity had a historical issue with arithmetic overflows and underflows, that's why having SafeMath enabled was a necessity back in the day. SafeMath has been made obsolete starting from Solidity v0....

View answer
String compare function works when defined in contract but not in library
Accepted answer
1 votes

I'm not sure what you're doing wrong at the implementation contract, but I've been able to successfully use your lib. Code: // SPDX-License-Identifier: MIT pragma solidity 0.8.9; library StringLib { ...

View answer
Chainlink custom token(pair) price
1 votes

You have two options: Contact Chainlink in order to get them to deploy your price feed and they'll give you a quote for the feed deployment and maintenance. This is the typical route of how projects ...

View answer
layer 2 solution best option
1 votes

For now, I would say the best options still seems to be Polygon. Although it's still a sidechain to be exact, and not yet a layer 2 solution. My reasons for choosing Polygon are: It is still where ...

View answer
Ownable in upgradeable contracts
Accepted answer
1 votes

You simply need to call the init method of OpenZeppelinUpgradesOwnable, which is __Ownable_init(), inside your initialize(...) method body. Also, remember to use the initializer to so as to restrict ...

View answer
How to write test case for the require function
Accepted answer
1 votes

You can expect a function call to revert and assert the error message upon reverting as follows: await expect(<YOUR FUNCTION CALL HERE>).to.be.revertedWith(<YOUR `REQUIRE` ERROR MESSAGE HERE&...

View answer
Does the etherscan api work with bsc chain?
Accepted answer
1 votes

From Etherscan API docs: Every block explorer built by Etherscan ( eg. BscScan, PolygonScan, HecoInfo ) requires a different account to be created and hence a different set of API keys Apparently ...

View answer
Run my own full node for prevent front running
Accepted answer
1 votes

I were in your situation a few months back. The easier and more efficient option would be to seek a dark pool to keep your transaction safe from the public mempool. If your transactions are not ...

View answer
What do I need to be careful about when using block.timestamp?
1 votes

One instance where you'd need to be extra careful would be to avoid using block.timestamp as a source of randomness. block.timestamp often produces pseudo-random numbers and it might be tempting to ...

View answer
Can a contract create a transaction that may trigger a change of state on ethereum network?
Accepted answer
1 votes

Contract accounts can't initiate any transaction on their own. You can program a contract to deploy another contract or a set of contracts, but the initiation would always have to be triggered by an ...

View answer
ERC-721 testing with JS - ReferenceError: use is not defined
Accepted answer
1 votes

The problem is with the following lines: require('chai') use(require('chai-as-promised')) should() These should be chained calls, and so should re-written as: require('chai') .use(require('chai-as-...

View answer
How to create a pool from scratch?
Accepted answer
1 votes

If you're building your own Uniswap clone, you would need to first deploy the factory and then use it to deploy your trading pools (token pairs) by calling: factory.createPair(tokenA, tokenB) If you'...

View answer
Is it possible to intercept a message sent to a smart contract (i.e. a guess for a quiz) and send it as your own before the original reaches it?
Accepted answer
1 votes

Yes, this is entirely possible if you constantly watch the public Ethereum mempool. Any transaction you execute would have to be first placed in the mempool, then it would linger there until picked by ...

View answer
Is it possible to generate unique, non-duplicate, random numbers in solidity?
1 votes

In practice, it's really difficult to generate a psuedo-random number in Solidity without compromising on security. In most cases, you would have to use a randomness oracle service. And for that, I ...

View answer
How to decide SPDX license for a smart contract?
1 votes

You need to first learn about software licensing and open-source licensing, and then decide which licence best fits your needs. Then, once decided: Place it in your SPDX license field. Place LICENSE ...

View answer
Way to tackle arbitrage bots
1 votes

Ok, here's what's happening: I'm almost sure there exists another exchange with a lower price for the pair, otherwise the arbitrage opportunity wouldn't exist. The pair creation tx was enough to ...

View answer