Solidity

How to integrate smart contract via web3 and infura provider

◇◆丶佛笑我妖孽 提交于 2019-12-11 07:36:33
问题 I have created a project with infura provider const web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/07630919731949aa87a45b96c98a834d')) And I try to call a smart-contract's method { to: addressTo, from: addressFrom, data: { name: 'addWhitelisted', inputs: [{ name: 'account', address: '0x57e755461FF79176fC8f14B085A8CBb4AE1fC2f6' }] } } Then I need to sign a transaction and call web3.eth.sendSignedTransaction ? But when i sign i get an error. Pls help. What I'm

How to compile solidity using solc 0.5

时光总嘲笑我的痴心妄想 提交于 2019-12-11 05:58:14
问题 compile.js : const path = require('path'); const solc = require('solc'); const fs = require('fs-extra'); const buildPath = path.resolve(__dirname, 'build'); fs.removeSync(buildPath); const campaignPath = path.resolve(__dirname, 'contracts', 'Campaign.sol'); const source = fs.readFileSync(campaignPath, 'utf8'); var input = { language: 'Solidity', sources: { 'Campaign.sol': { content: source } }, settings: { outputSelection: { '*': { '*': [ '*' ] } } } } const output = solc.compile(input, 1)

Can't call contract function in truffle console

你离开我真会死。 提交于 2019-12-11 04:16:37
问题 I'm compiling and deploying the following contract to testrpc: pragma solidity ^0.4.4; contract Adoption { address[] public adopters; function adopt(uint petId) public returns (uint) { require(petId >= 0 && petId <= 15); adopters[petId] = msg.sender; return petId; } } Then I go to terminal and: truffle compile truffle migrate --reset Everything works as expected. Then, I try to call adopt() in truffle console: truffle(development)> const adoption = Adoption.deployed() // undefined truffle

Solidity: Can a Parent contract see data updates from a Child contract?

妖精的绣舞 提交于 2019-12-11 01:44:45
问题 I have a premature implementation of an Ethereum game. I have divided my code in two contracts, separating "game" functions from functions called by the Admin. Admin.sol inherits from Game.sol as seen below. A struct object is created in Admin, but Game cannot see it. (Getter function returns nothing) import "./Game.sol"; contract Admin is Game The same code, if not divided in two contracts, works perfectly. Header of function in Admin.sol that creates the object: function createJob(string

How solidity make function signature with tuple(nested abi)?

∥☆過路亽.° 提交于 2019-12-11 01:17:15
问题 struct Test { uint ui; string s; } function test(Test t) public { emit Log(t.ui, t.s); } I have some knowledge about ABI. I made this contract with experimental ABIEncoderV2 option. In conclusion, this function's signature is 0x6056f4cc, I found this value in opcode. I tried some case test(uint256,string), test(tuple(uint256,string)), test(tuple), test(tuple[uint256,string])) with sha3... but no one make correct signature. How solidity make function signature with tuple? 回答1: You're close

Render JavaScript number as solidity ERC20 decimals

梦想与她 提交于 2019-12-10 20:41:56
问题 When you create an ERC20 cryptocurrency in solidity you initialize it with a number of decimals. If you total supply is 10k and the number of decimals is 4, your token supply will display as 100000000 (10,000.0000). In Solidity, you simply do YourNumber*10**4 to initialize a number like 10,000.0000 where YourNumber = 10,000 I wanted to do a simple calculator in JavaScript where, based on the user input we give them their input in decimals of a token. Say the maximum number of decimals is 4

Is there a pop functionality for solidity arrays?

谁说我不能喝 提交于 2019-12-10 13:57:12
问题 I have used solidity to push data into an array. Is there a similar function for pop ? string[] myArray; myArray.push("hello") What is the best solution for this ? How do I delete an element in a dynamic array in solidity ? 回答1: Update 2-19-2019 : As Joel pointed out below, pop has been added to built-in array support. See https://solidity.readthedocs.io/en/v0.5.4/types.html#array-members. Leaving original answer on here in case others are using older versions of Solidity. There is no pop

Different ways to invoke contract method

空扰寡人 提交于 2019-12-09 03:56:08
问题 I have one contract with method name as getValues().From Dapp I am invoking contract method as 'contractCAt.getValues.call(function(error,result){...})' this works fine and by using 'contractCAt.getValues(function(error,result){...})' this syntax also works fine.I didn't get any difference between those two ways to invoke contract method.So could anyone help me to give idea about those syntax. 回答1: See the web3j documentation: contractCAt.getValues.call() is run locally and will not alter the

Storing and Retrieving Data in Ethereum Blockchain

放肆的年华 提交于 2019-12-08 15:24:28
I am a beginner in blockchian and I want to store a personal demographics data in a ethereum blockchain via solidity.I have some basic questions regarding that: Do I have to store the data in a smart contract ? Say I store multiple personal data in the blockchain , in that case would each personal data get stored in separate blocks using the same instance of the smart contract ? Are there any open source tools through which I can view the blocks in my local ethereum block chain? I will try to answer this in easy terms. Do I have to store the data in a smart contract ? Yes you need to store the

How is the source code protected from being tampered with in a blockchain?

懵懂的女人 提交于 2019-12-08 05:16:01
问题 class Block{ constructor(timestamp, transactions, previousHash = ''){ this.timestamp = timestamp; this.transactions = transactions; this.previousHash = previousHash; this.hash = this.calculateHash(); this.nonce = 0; } calculateHash(){ return SHA256(this.previousHash + JSON.stringify(this.transactions) + this.timestamp + this.nonce).toString(); } mineBlock(difficulty){ while(this.hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")){ this.nonce++; this.hash = this.calculateHash();