ethereum

Questions about contract calling another contract

强颜欢笑 提交于 2019-12-06 10:48:05
Need help with two related Solidity questions. Question 1. Say, I have a contract calling another one: contract B { function f1() { ... } } contract A { B b; function f() { b.f1(); } } Will msg.sender for f1 be same as for f() ? Of will it be an address of a contract A ? Question 2. Say, I have contracts A and B. I want to have contract A { B b; A(address addr) { b = B(addr); } } In other language, I would use B b = null; in declaration, to avoid double initialization, but it does not work in Solidity. So how do I declare a member variable and then initialize it by address? Will msg.sender for

Dynamic array in Solidity

▼魔方 西西 提交于 2019-12-06 07:48:44
问题 I a very new to Ethereum and Solidity development. I just want to declare a simple array ( dynamic list ), one set function to push string in that and one get a function which returns all the strings saved in the dynamic array. I search a lot but not able to find this simple stuff. Thanks in advance 回答1: Here is my solution, you need experimental ABIEncoderV2 to return array of strings. pragma solidity ^0.5.2; pragma experimental ABIEncoderV2; contract Test { string[] array; function push

Solidity - Solidity code to Input JSON Description

谁都会走 提交于 2019-12-06 04:09:40
I want to compile my ehtereum HelloWorld.sol smart contract. In all the tutorials is that you do it like this: var solc = require('solc'); var compiledContract = solc.compile(fs.readFileSync('HelloWorld.sol').toString(); where HelloWorld.sol is: pragma solidity ^0.5.1; contract HelloWorld { bytes32 message; constructor(bytes32 myMessage) public { message = myMessage; } function getMessage() public view returns(bytes32){ return message; } } In other words I put my raw Solidity contract code into the solc.compile() method. But this process gives me this error in compiledContract: '{"errors":[{

Out of gas while migrating a contract

霸气de小男生 提交于 2019-12-06 03:29:33
I have looked at the other "out of gas" SO posts and they haven't solved my problem. I am using ganache-cli started with ganache-cli --account="0xce2ddf7d4509856c2b7256d002c004db6e34eeb19b37cee04f7b493d2b89306d, 2000000000000000000000000000000" I then execute truffle migrate --reset It returns with an error Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: VM Exception while processing transaction: out of gas (Full error is at the end) These are the files involved; truffle.js module.exports = { networks: { development: { host: "localhost", port:

How to get Ethereum transaction list by address

半城伤御伤魂 提交于 2019-12-05 18:11:26
I'm looking for a way to get a list of transactions for a given address. If there are too many transactions I'd expect to be able to page the results. It would be better if I can give the latest processed transaction as parameter so I could get the latest transactions from a given point. Something like this: var page = 1; txList = getTransactionList("0x323432432...", page, lastProcessedTx); From my research so far there is no way to get transaction list for an address. You should check all the transactions in the blockchain for the given address or relate addresses to transaction hashes in a

Repeating transactions hangs - web3js, local geth

旧巷老猫 提交于 2019-12-05 17:34:32
I have an issue with transactions on my local ethereum network - at some point, transaction hangs & spends a lot of ETH from my account. Here's a sample code: async function send(toAccount, weiVal) { let account = await w3.getDefAccount(); for (let i = 0; i < 100; i++) { let res = await web3.eth.sendTransaction({ from: account, to: toAccount, value: weiVal }); await helper.timeout(2000); } } send('0x5648...', 100000000000000); It hangs at sendTransaction call (promise is never resolved) on some random iteration. The situation remains the same after script restart - transaction passes a few

My ethereum balance seems to be 0 when checked via geth

血红的双手。 提交于 2019-12-05 16:19:40
I created an ethereum address geth account new and sent some ethers to it. Then I ran the server: geth and the JavaScript console: geth attach I checked the balance, but it was 0: > eth.getBalance('0xB97168a67AB66E55B98B1439222Ee665E657fFc0') 0 When I checked the balance via etherchain , there were some ethers. What am I doing wrong? It is possible that you are not allowed to participate in the public ethereum network, because your local time might be incorrect (if you are off by 12 seconds it can cause problems already!) or because of your firewall configuration. Check these common

Remix错误

六月ゝ 毕业季﹏ 提交于 2019-12-05 12:20:58
在刚开始使用Remix在线IDE编写solidity智能合约时,你可能会碰到这个错误: Mock compiler: Source not found 。怎么会这样?应该怎么解决?本文 将解答这个问题的起因及解决方案。 错误现象 当你尝试使用Remix时,有可能会看到下图: 出现 Mock compiler: Source not found 这个错误的原因,是启动的Remix环境没有 选中合适的Solidity编译器。例如,你可以点击下面链接重现这个错误: <a href="https://remix.ethereum.org/#optimize=false&version=builtin" target="_blank" rel="nofollow external"> https://remix.ethereum.org/#optimize=false&version=builtin </a> 解决方案 在Remix环境 Settings 选项卡中,选择合适版本的Solidity编译器即可。例如: 另一种解决方案是在URL中直接指定solidity编译器的版本,例如,使用下面的链接: <a href="https://remix.ethereum.org/#optimize=false&version=soljson-v0.4.24+commit.e67f0147.js">

How do I connect to a private network from ethereum wallet?

做~自己de王妃 提交于 2019-12-05 07:23:55
How do I connect to a private network from ethereum wallet? I was able to create a private network from geth command line using custom genesis file but now wanted my ethereum wallet to point to custom genesis file of the private network.Currently I am able to point my etherem wallet to either the mainnet or testnet but not private network. I did find the following instructions on github mist browser Readme file but haven't been able to make much progress To run a privatenet you need to have geth installed separately and run it with the ipcpath flag: $ geth --networkid 1234 --ipcpath /Users/you

以太坊(Ethereum)开发框架 Truffle 入门(二):选择一个以太坊客户端

主宰稳场 提交于 2019-12-05 07:16:50
有许多以太坊客户端可供选择,我们建议在开发环境和部署环境使用不同的客户端。 在开发环境 EthereumJS TestRPC: https://github.com/ethereumjs/testrpc 当开发基于 Truffle-based 的应用程序,我们推荐使用 EthereumJS TestRPC 。它只在你的开发机器内存里运行一个完整的区块链。它立即处理事务而不是等待默认阻塞时间——所以你可以更快速测试你的代码——它会立即告诉你当你的智能合同中发生了错误。这也使得自动化测试大客户端的时候 Truffle 知道如何运用它的特殊功能以节省近90%的测试时间。 在部署环境 Geth (go-ethereum): https://github.com/ethereum/go-ethereum WebThree (cpp-ethereum): https://github.com/ethereum/webthree-umbrella 更多: https://www.ethereum.org/cli 有许多官方的和非官方的以太坊客户端供你选择。当你已经充分使用 EthereumJS TestRPC 测试你的 DApp 并且你准备把它部署到以太坊网络,你应该使用这些客户端。这些都是完整的客户端实现,包括采矿、网络、区块和事务处理,并且 Truffle