New answers tagged

0

function createProduct(string memory _name, uint _price, string memory _info, uint _quantity) public payable { This function signature has _price in ethers. So try changing the default units to the ether from Wei and send the appropriate price of the product. Mine is working [vm]from:0x4b0...4d2dbto:Buyproduct.purchaseProduct(uint256,uint256) 0x1df......


0

I myself go the answer (thank God, finally). I am giving the details in case anyone in future get some helps from it. The point is atom is not supporting any .json file starting with : . Thus what we have to do is to replace it with empty string, i.e. path.resolve(buildPath, contract.replace(':', '') + '.json' ), Also make sure to use the .sol version ...


0

The Campaign.sol file has 2 contracts named CampaignMgr and CampaignFactory The basic input unit for the Solidity compiler is a contract, not a file: If you create one file for each contract, and you use the same name for the file and for the contract, then yes - you get one artifact per file, with the exact same name If you create one file for each ...


1

In your case there is no interactions between smart contracts. HelloWord.getSaluto() is actually an internal call, i.e. your smart contract calls its own function, just defined in base smart contract. Real interaction scenario would look like this: contract A { uint state = 0; function foo (uint x) public returns (uint) { return state += x; } } ...


0

Delete all files in the build\contracts folder. That fixed the error for me.


2

It's probably easiest to accomplish with a modifier which you add to each function. So something like this: pragma solidity 0.6.0; contract Example { bool _isActive = true; modifier checkActive() { require (_isActive); _; } function do1() checkActive public { // do something } function do2() checkActive ...


0

In order to store a string and access it, you can do the following: pragma solidity ^0.6.5; contract SimpleStorage{ string storeddata; function set(string memory x) public{ storeddata = x; } function get() public view returns(string memory){ return storeddata; } } A few notes on the differences between this code and ...


0

Following the etherscan-link that you have posted in a comment to your own question: From: 0x87ee3337108a31ab539e244f3d22f4070f03d12a To: Contract 0x812a27078f0644b5bb88d5c0b9d616eb3550bcec Function: transferFrom(address _from, address _to, uint256 _value) [0]: 00000000000000000000000018c7abf493c747f39ce006abeb9bd6d2592e833e [1]: ...


0

The method you described would work. A cost optimization would be to log an event whenever a user sent their tokens to the contract. This would remove the requirement for both an array and a mapping. When attempting to read the data off-chain (for the swap to the other token), you can simply read each event that occurred on that contract. An example would be:...


0

// Web3 v1.2.6 const Web3 = require('web3'); const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); const contractJSON = require('/path/to/build/contracts/Contract.json'); const contractInstance = new web3.eth.Contract(contractJSON.abi, 'CONTRACT_DEPLOYED_ADDRESS'); async function getTimeFromContract() { const time = await ...


0

It depends on how you have deployed your contract. If it was deployed correctly then you can call. einstance.functions.getTime().call() where einstance must be instance of web3._utils.datatypes.Contract. Little brief on how to install your contract Step1: Compile your contract and get the bytecode and abi. You can install a specific version of sold ...


0

I'd suggest to upgrade to solidity 0.5. The constructor have an invalid syntax error. It should be something like this function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = 250000000 * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // ...


1

If you are using web3, you can encode it with: web3.eth.abi.encodeParamter('string', <lorem_ipsum_text>) You can then decode the output with the following: web3.eth.abi.decodeParamter('string', <lorem_ipsum_encoded_string>) Encoding is based on the Contract ABI Specification. It is hard to get through, but these docs have all the answers to ...


0

From purely a cost perspective, all that matters is the number of slots (32 bytes) used. The storage costs on Ethereum are on a per-byte basis. Ethereum's Keccack-256, as the name implies, is 256 bits, or 32 bytes. The number of bytes for the RIPEMD hash depends on the algorithm chosen. If you use RIPEMD-128 or RIPEMD-160, you will use 16 bytes and 20 ...


1

I tried the deployed contracts and they work as expected. KombuchaProxy shouldn't update Kombucha contract. It updates its own storage. The whole idea of a proxy is that it contains the data and point to another contract that has the code. To test this in Remix I instantiated Kombucha contract at KombuchaProxy address. Now you can execute Kombucha ...


1

The more realistic situation will be to send from 100 different addresses. From an ethereum client perspective there is some difference but not much. For a miner it should not matter. Once the proposed block is created by the client the proof of work algorithm execution will be the same.


1

That BN stands for BigNumber. It's a JavaScript framework for representing..well...big numbers. If you simply console.log a BigNumber it will give you such internal data of the single BigNumber, such as those length and words. Those are not trivially interpretable. So what you should do it simply .toString() it to get the actual number. It really is just ...


1

You cannot retrieve the original source code anymore, if no copy is available. The only way is to decompile the EVM bytecode to get a source code that is equivalent, but not equal to your original source code (it will look different but do the same). When you compile your Solidity code to EVM bytecode, the constructor is still included. After the contract ...


1

According to your link to etherscan, the transaction is: From: 0x2b9c37a4a6f27a95a790a9935a998123167425f0 To: Contract 0x5d3a536e4d6dbd6114cc1ead35777bab948e3643 And the method invoked on that contract is: Function: redeem(uint256 redeemTokens) This function calls another function and so on, but the important part is that at some point during the ...


1

Constructor arguments are passed during deployment, not during compilation.


1

It's not possible to read previous state in Solidity or EVM. The only information which can be obtained from the past is the block hash (only for the last 255 blocks). In this case you would need to check if a contract's address had code attached before a block number. That block number would represent 2020-01-01, any address that did not have code before ...


0

Let me try to put this in a simpler way: When MultiSigWallet is deployed it takes an array of owners and the number of confirmations required for executing a transaction. function MultiSigWallet(address[] _owners, uint _required){ //Logic } The purpose of multisig wallets is to increase security by requiring multiple parties to agree on transactions ...


1

You have to covert the arguments to a bytes. abi.encodePacked(args) is a way to do it. pragma solidity 0.5.9; contract test{ //https://github.com/ethereum/solidity/issues/3469 address payable owner; mapping (address => bool) pd; uint public sS; function lnA(address addr) public view returns(uint8 n) { // 1 in 8 chance ...


1

Each token has exactly one token contract which acts as the token ledger. A token contract is typically for just keeping track of that one token - who owns and how many of said token. A token contract typically cannot manage other tokens. In theory you can add such functionality into one but it would not be a very good idea. If you want to have some way to ...


0

One problem with encrypting data and putting it on chain is that you're leaving your encrypted data on a public immutable data store forever. What if some radical new computing paradigm (quantum?) can break the encryption, or your keys are stolen? This problem is one that the Baseline Protocol is aiming to solve, see: https://docs.baseline-protocol.org In ...


0

From Solidity read the docs: Array: Arrays can have a compile-time fixed size, or they can have a dynamic size. Indices are zero-based. Takeaway: Solidity does not support heterogeneous arrays yet, i.e. the indices for arrays are integers and not any other value. Mapping: Mapping types use the syntax mapping (_KeyType => _ValueType) and variables of ...


0

Instead of trying to convert address to raw bytes, it is often easier to use ABI encoding. ABI encoding is not raw byte-to-byte translation, but it adds its own marker bytes to separate fields. However you can perform this with one built-in function. In Solidity /** * A test method exposed to be called from clients to compare that ABI packing and ...


1

If you need any of the following to run in O(1) operations: Get an item by unique ID which is not a sequential number (e.g., an address) Remove an item Then an array is inappropriate, and you must use a mapping.


0

You can access only one element of an array with the automatically generated getter method (the argument passed is the position of the array to return, default is 0). To get the full array, you need to write a getter yourself that returns an array. Also, I recommend you use a mapping instead of a dynamic array: contract TestChainStorage { ... ...


2

If a transaction receipt shows the to field empty and an address in the contractAddress field, does it mean that the specified contract was created? Yes, it implies that a contract was deployed at the address specified in the contractAddress field. And the exact opposite implies that the transaction was sent to a contract which has already been deployed at ...


2

If the to field is empty it is most likely a transaction that deployed the smart contract, found in the contractAddress. logs contain emitted events from Solidity. You can match them to actual ABI events using web3.py Contract API. logs are optional. Smart contracts may not emit them and they are not present in account to account transfers. Hope this ...


Top 50 recent answers are included