New answers tagged

0

Although the complete code is not visible and according to my observation, you are missing the web3.js package so before this script you can add <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>


0

To answer your URI question - if you want to use IPFS then you should install IPFS CLI to create a local node and upload your file to get a hash generated which you can use to create your URI. https://docs.ipfs.io/install/command-line/ If you want an example on how to mint an NFT using ERC721, IPFS and some basic toolchain try out this example from Patrick ...


0

From a code perspective, the owner is simply able to transfer contract's balance to them at their whim. But, token contracts which are legitimate generally don't implement ether transfers to owners atleast. Maybe because the contract can use the mint function and increase it's supply which can then permit the owner to swap those newly minted tokens on a DEX ...


0

Solidity has an SMTChecker which makes using assert very cool because it can prove that your invariants are true: Solidity implements a formal verification approach based on SMT (Satisfiability Modulo Theories) and Horn solving. The SMTChecker module automatically tries to prove that the code satisfies the specification given by require and assert ...


0

The token that is being transferred will call the IERC721Receiver methods. Therefore you can use msg.sender to detect the address of the token that is being transfered. The ERC721 smart contract calls this function on the recipient after a transfer. This function MAY throw to revert and reject the transfer. Return of other than the magic value MUST result ...


2

Metamask doesn't expose private keys as it's a huge security issue. You shouldn't expect users to expose their private keys either. If you want to sign a transaction or arbitrary data, you can use the Metamask RPC methods. You can find the methods here. With this, you can perform data signing, encryption-decryption with the private keys, in a safe way.


0

Are you creating both token A and token B, just token B, or neither? It sounds to me like you're creating both of them? Correct me if I'm wrong here, but to sum up it sounds like you're creating contracts for ERC20 tokenA and ERC20 tokenB, and whenever an amount of tokenA is transferred, you want the same amount of tokenB to be transferred to the same ...


0

const busdAbi = [ "event Approval(address indexed owner, address indexed spender, uint256 value)", "function approve(address spender, uint256 amount) external returns (bool)" ]; // retrieve the BUSD contract busdToken = await ethers.getContractAt(busdAbi, BUSD_ADDRESS?BUSD_ADDRESS:'', deployer)


0

ABI (Application Binary Interface) in the context of computer science is an interface between two program modules, often between operating systems and user programs. EVM (Ethereum Virtual Machine) is the core component of the Ethereum network, and smart contract is pieces of code stored on the Ethereum blockchain which are executed on EVM. Smart contracts ...


0

First, check if your transaction's setup(gas/gas limit) is ok (see this). If everything is okay, the most probable issue might be the size of your contract. I suggest first take a look at this to get familiar with contract deployment's gas calculation. Now, note that each block has a limited size(currently it is 15 million gas). This means that you cannot ...


0

This is bad contract design in my opinion. You can just store the mapping in Bank.sol and have the same functionality. You are also using double the gas required. Is it because BankMediator has 0 eth thus not able to pay any gas fee? How can I make wallet pay gas fee even for withdrawal? No. All gas is paid for by the user. Contracts do not pay gas as ...


1

calldata represents the data of the (internal) transaction. This data cannot be adjusted inside a call, therefore you cannot write into calldata. There are two ways to go ahead with this: Have the data be provided by the sender that calls your method and define it there as a calldata parameter. Perform an internal transaction to the schedule method (which ...


1

I think is because you must install the dependency first and then import like you are doing with Counter.sol. import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; Be sure that you run yarn add @openzeppelin/contracts or npm install @openzeppelin/contracts


0

As @Patrick Collins said above, using Chainlink and calling getLatestPrice() would work. But what you could also do is have a function that determines the price by calling the getLatestPrice() on every transaction, i.e. when someone wants to buy, you call getLatestPrice() and in that function, you can calculate the USD equivalent of ETH.


0

It happens to me when I type fast, I leave blank brownie run scripts /fileName.py It should be brownie run scripts/fileName.py


0

@Crazy, using the technique brought by @Ismael, I created one, however I'm still in doubt about any possible security issues on that: Using ECDSA to verify a signature inside smart contract


1

Per https://github.com/ethers-io/ethers.js/issues/2000, you can do: await lockedToken.connect(multisig).addAdmin(escrow.address);


0

Masterchef (originally by Sushiswap, based on Synthetix Rewards contract) is very popular and him and it's variants are used all over the place.


1

Unsure if you mean deployed contracts or undeployed/templates. Here are my takes for both. Deployed: Uniswap (all versions) Opensea contracts MetaMask swap Aave Undeployed/templates: OpenZeppelin ERC20 & ERC721 Gnosis Safe


1

Keyword payable in the function is needed to make the function able to receive ether. Sending ether is possible from any function, as long as the address sending is payable.


1

The key to solving this (how we do it at least) is using array indexes. It's still tricky as in Solidity we are very limited in what we can do with arrays, there is no way to slice, flip etc. Here is a working approach. (Note: this assumes you fulfil randomness via chainlink or otherwise in the getRandomNum function. Modify accordingly.) // your array which ...


1

This kind of things are simply easiest to try out in something like Remix. I tried all three variants: as-is, explicitly setting i and explicitly setting result . The first two cost the same (25315), and the last one costs 25323. Honestly, I'm really not sure why it's like this.


0

This issue was totally my bad: Not visible in the sample I provided is some code that mints a small amount of tokens to the miner of the block. (Not sure why (it was a long time ago)). On the blockchain, this would have worked just fine, but I was testing locally using truffle's Ganache. Because Ganache is only a test blockchain, there are no miners, and ...


0

//heres an updated version. thanks for you guys input.// // SPDX-License-Identifier: MIT pragma solidity 0.8.4; contract Alex{ string public name; string public symbol ; uint256 _totalSupply; uint8 public decimals ; uint _publicmoney; address public myaddress=address(this); event Transfer(address indexed _from, ...


0

Since you want to use the blockchain to store the information, I recommend a contract factory pattern. So you should have one contract factory contract. That contract acts as a factory: it creates contracts upon demand. At the same time, it keeps track of who has deployed what contract. Whenever you need information about who has deployed what, you just ...


0

It is all about operation cost. All exchanges have to transfer every deposits to cold wallet to secure the funds. Lets use USDT deposit as an example For Externally Owned Accounts (EOA)/new deposit address approach, below steps are needed: Exchange generate addresses for each user (Free) User deposit USDT to their address in step 1 Exchange send ETHER to ...


0

for me it works if I declare the msg.sender as a address variable at the start of my constructor contract Test is ERC20{ address public OWNER; uint private _totalSupply = 500000; constructor() ERC20("Test Token ERC20", "T20"){ OWNER = msg.sender; _mint(OWNER, _totalSupply); } }


0

Okay, it seems like on the initilizing function the parameters were being shadowed, that made the value of the divisionFeePrice to be 0.


1

Each web3 javascript library will expose the contract methods in its own way. From the intro page of Ethernaut: ethernaut is a TruffleContract object that wraps the Ethernaut.sol contract that has been deployed to the blockchain. We can see that their contracts are instantiated as @truffle/contract which has a method calling procedure that looks like: ...


0

Since solidity 0.8.x you can do import { contractA } from "contract/path/1"; import { contractB } from "contract/path/2"; This will prevent the shadow import of contractB if it is also used in contracA


0

Insert the amount you want to pay in the Value field in Remix. It is at the top, above the functions you're calling.


0

Add pragma solidity 0.8.0; at the top of the .sol file. This is how you choose your solidity language version.


0

Ethers it's pretty similar to web3 regarding getTransactionCount. Reference await provider.getTransactionCount('ricmoo.eth'); // 26 Using the "pending" switch you can get the number of non mined tx for that address await provider.getTransactionCount('ricmoo.eth', 'pending'); // 2 Beware though: it's quite unreliable. The pending blockTag is not ...


0

% is the modulo operator, it gives the remainder after integer division. In your case, 83 % 7 = 6 + 1 = 7 You can find more details about modulo and other operators inside the official Solidity documentation.


0

Possible answer: Instead of checking if the sender == deployer, I opted to check if the recipient == deployer and it is working as intended (seemingly). I assume it is due to how exchanges handle transfers during a swap?


0

There is an inbuilt variable called owner(), that is used for just such a thing. (Because your contract is Ownable.) So your code would look something like this contract token is ERC20, Ownable { using SafeMath for uint256; uint taxPercentage = 9; constructor(uint256 initialSupply) ERC20("token", "tkn") { ...


0

You can "integrate both contracts" The way to solve this is to deploy them separately (as you seemed to have guesed). Just make sure that Factory contracts has a function named SetChildContractAddress(_address) SetChildContractAddress(_address){ CHILD =Child(_address); //Child variable needs to be declared prior } Once you have deployed both ...


1

By definition of EIP-214 any state change within a static call will cause an error. So if you define your function as view or pure this will not be possible, as this indicates the calling contract that they should use staticcall. BUT if you want to write a method and don't care about the view or pure you can do a little trick. You create a method that will ...


1

From the ethers documentation we can see that contract.callStatic is an utility that interacts with the node itself. It works by asking the node to simulate the transaction, without the tx being actually sent to be mined. A similar behaviour isn't available at a smart contract level as any state change is permanent if not reverted. A workaround could be re-...


0

When you swap an ERC20 token for ETH on Uniswap, the token's transfer function is called - see IERC20.transfer. IIRC when you "buy" your wallet is the recipient and the Token-WETH pair contract (created by the Uniswap Factory) is the sender. On the other hand, when you "sell" your wallet is the sender and the pair is the recipient. If you'...


0

In newer versions of Remix, use the field named Value above the deploy button. It is the same field that is used to choose the initial contract balance on deploy when the constructor is payable. Then click the button that calls the payable function that you need.


1

I didn't quite understand the depth of the idea, but maybe this option will help: function store(uint256 _myVal) public { myVal.push(_myVal); for(uint256 _y = 0; _y < myVal.length; _y++) if(_y<_arr.length) _arr[_y]=myVal[_y]; else _arr.push(myVal[_y]); }


2

Interface and contract types in solidity are just compile time wrappers around an address. If you look at the generated abi filed for your code you will see that the parameter type expected is an address. And actually the generated bytecode will not perform any type checks on this address. If you want to check if a specific address implements an interface I ...


0

There is an import of a library that makes it possible with a int-to-string function, taken from How to convert uint to string in solidity?. solidity ^0.8.0 import "@openzeppelin/contracts/utils/Strings.sol"; Strings.toString(myUINT)


0

the network appears to be working now so the problem is solved.


0

On Geth version 1.10.12, you can call your get method like this: link.get.call() Also, instead of constant, include the view and public modifiers to your get function definition in Solidity. If your function isn't returning any value, you can call it directly without the call method like this myContract.myFunction()


0

If someone, like me, was trying to understand how to set some value to msg in Remix for a test, the trick is this: ///#value: 100 function testSomething() payable public { Assert.greaterThan(msg.value, uint(50), 'value should be > 50'); } If you run this code above it will be OK. Because you need to put "///#value: {desired value}" - With ...


0

In trying to solve this problem I have come across the "polygon state sync" (thank you 0xTomoyo :-)) https://docs.polygon.technology/docs/contribute/state-sync/state-sync/ It looks like this requires the addition of an emitter on the ETH contract side, but should do the trick. Also, it looks like chainlink is heavily developing solutions for this ...


0

I was having the same problem with the Opensea contract, and, while I am not sure if this code is the one running the Opensea Storefront, the error message matches. Let's have a look at the overriding safeTransformFrom function: function safeTransferFrom( address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data ) ...


0

Alternatively you can change the default network to the testnet you are deploying on. If I'm not mistaken brownie will launch and connect to ganache-cli by default. You can refer to the documentation here https://eth-brownie.readthedocs.io/en/stable/network-management.html#live-networks, or refer to the picture below


Top 50 recent answers are included