该代码产生相同的输出。
pragma solidity ^0.5.0;
contract mycontract
{
function add(uint c, uint d) public pure returns(uint)
{ uint e=c+d;
return e;
}
function add(uint j, uint k) public view returns(uint)
{ uint f=j+k;
return f;
}
}
Run Code Online (Sandbox Code Playgroud) functional-programming blockchain ethereum solidity smartcontracts
我有一个结构购买,其中我正在进行一系列付款.但是,当我尝试在我的makePayment方法中添加新的payment数组时,我从solidity编译器返回错误:"内部编译器错误:将类型struct Payment memory []内存复制到尚不支持的存储." 当我将mayment数组更改为storage或时memory,我得到相同的错误.我在下面添加了相关代码.
有可能做我想做的事情吗?我没有看到任何明确说明它在文档中不可能但我也没有看到任何示例正在做我正在尝试做的事情.:|
struct Payment {
address maker;
uint amount;
}
struct Purchase {
uint product_id;
bool complete;
Payment[] payments;
}
Purchase[] purchases;
function makePayment(uint product_id, uint amt, uint purchase_id) returns (bool) {
Payment[] payments;
payments[0] = Payment(address, amt);
purchases[purchase_id] = Purchase(product_id, false, payments);
}
Run Code Online (Sandbox Code Playgroud) 我遇到了一个相当普遍的问题,似乎我无法优雅而有效地解决问题.
我要将一个任意长的任意长字符串数组传递给一个可靠的契约.
在我看来它应该是这样的
function setStrings(string [] row)
Run Code Online (Sandbox Code Playgroud)
但似乎无法做到.
我怎么解决这个问题?
我试图在我的ERC20令牌合同上调用一个方法.我正在连接到" https://rinkeby.infura.io/"httpProvider.我可以调用()常量方法,但是当我想通过调用send()函数来改变契约的状态时,我得到了这个提到的错误.如果您认为发布ABI JSON或Solidity合同有帮助,我也可以提供.我认为我的问题纯粹与web3有关.我想我需要签署交易(逻辑上),但web3文档没有提到任何内容.http://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-send
这是我得到的错误:
Unhandled rejection Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (/opt/backend/node_modules/web3-core-helpers/src/errors.js:42:16)
at XMLHttpRequest.request.onreadystatechange (/opt/backend/node_modules/web3-providers-http/src/index.js:60:32)
at XMLHttpRequestEventTarget.dispatchEvent (/opt/backend/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/opt/backend/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/opt/backend/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/opt/backend/node_modules/xhr2/lib/xhr2.js:469:24)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
From previous event:
at PromiEvent (/opt/backend/node_modules/web3-core-promievent/src/index.js:35:24)
at send (/opt/backend/node_modules/web3-core-method/src/index.js:446:21)
at Object._executeMethod (/opt/backend/node_modules/web3-eth-contract/src/index.js:890:24)
at Object.currencyToken.sendSignUpBonousTokens (/opt/backend/server/common/token/currency-token.js:86:56)
at <anonymous>
Run Code Online (Sandbox Code Playgroud)
从调用此方法:
const Web3 = require('web3');
const Tx = require('ethereumjs-tx');
const …Run Code Online (Sandbox Code Playgroud) 我用这个例子写了Crowdsale .但我无法发送事务,我的测试失败并出现错误:
Contract: Crowdsale should accept payments after start:
AssertionError: expected promise to be fulfilled but it was rejected with 'Error: VM Exception while processing the transaction: revert'
Run Code Online (Sandbox Code Playgroud)
我试图将汽油价格设置为这样的交易,crowdsale.sendTransaction({value, from: buyer, gas: 4712388})但它对我没有帮助.
我的众筹:
pragma solidity ^0.4.16;
interface token {
function transfer(address receiver, uint amount) external;
}
contract Crowdsale {
address public beneficiary;
uint public fundingGoal;
uint public amountRaised;
uint public deadline;
uint public price;
token public tokenReward;
mapping(address => uint256) public balanceOf;
event FundTransfer(address backer, …Run Code Online (Sandbox Code Playgroud) 我正在Azure上的虚拟机上部署私有以太坊区块链(geth).在区块链上部署我的Solidity合同并启动我的NodeJS应用程序后,我能够通过nodejs Loopback App的web apis正常添加数据,一切正常,我可以使用GET apis查看添加的数据.
然而,在1-2-3天(随机)后,我无法检索通过我的GET apis添加的数据,而我仍然能够添加新数据,确认Geth正常运行并且没有中断.
我正在运行geth使用:
geth --datadir ./myDataDir --rpc --networkid 1441 console 2>> myEth.log
Run Code Online (Sandbox Code Playgroud)
myEth.log没有显示任何错误,nodejs日志也是干净的.
eth.syncing显示false哪个网络已同步.
myDataDir文件夹的大小仍然在增加,所以逻辑上数据应该在某处,但它没有显示.
我有一个节点js进程,它创建一个web3 websocket连接,如下所示:
web3 = new Web3('ws://localhost:7545')
Run Code Online (Sandbox Code Playgroud)
当进程完成时(我发送一个SIGTERM),它不会退出,而是永远挂起而没有控制台输出.
我注册了SIGINT和SIGTERM一个听众在什么处理过程中具有突出以观察process._getActiveRequests()和process._getActiveHandles(),我看到以下内容:
Socket {
connecting: false,
_hadError: false,
_handle:
TCP {
reading: true,
owner: [Circular],
onread: [Function: onread],
onconnection: null,
writeQueueSize: 0 },
<snip>
_peername: { address: '127.0.0.1', family: 'IPv4', port: 7545 },
<snip>
}
Run Code Online (Sandbox Code Playgroud)
为了完整性,这里是监听信号的代码:
async function stop() {
console.log('Shutting down...')
if (process.env.DEBUG) console.log(process._getActiveHandles())
process.exit(0)
}
process.on('SIGTERM', async () => {
console.log('Received SIGTERM')
await stop()
})
process.on('SIGINT', async () => {
console.log('Received SIGINT')
await stop()
})
Run Code Online (Sandbox Code Playgroud)
看起来web3正在打开一个套接字,这是有道理的,因为我从未告诉它关闭连接.通过文档和谷歌搜索,它看起来不像web3对象的close或end方法.
手动关闭stop …
在OOP语言中,继承的组合是众所周知的最佳实践.Solidity也是一种OOP语言,但也存在气体效率问题.
问题是,在Solidity中,考虑到各自的天然气成本,组成和继承如何相互比较?
我正在尝试使用npm solc编译可靠性智能合约.我试着遵循不同的例子.链接到示例:https://medium.com/coinmonks/how-to-compile-a-solidity-smart-contract-using-node-js-51ea7c6bf440
我编写了如下代码:
const path = require('path');
const fs = require('fs');
const solc = require('solc');
const helloPath = path.resolve(__dirname, 'contracts', 'hello.sol');
console.log("First" + helloPath);
const source = fs.readFileSync(helloPath, 'UTF-8');
console.log("Second" + source);
console.log(solc.compile(source, 1));
Run Code Online (Sandbox Code Playgroud)
运行上面的代码时出现以下错误.
AssertionError [ERR_ASSERTION]: Invalid callback specified.
at wrapCallback (C:\Users\mouazzamj058\solc_example\node_modules\solc\wrapper.js:16:5)
at runWithReadCallback (C:\Users\mouazzamj058\solc_example\node_modules\solc\wrapper.js:37:42)
at compileStandard (C:\Users\mouazzamj058\solc_example\node_modules\solc\wrapper.js:78:14)
at Object.compileStandardWrapper (C:\Users\mouazzamj058\solc_example\node_modules\solc\wrapper.js:85:14)
at Object.<anonymous> (C:\Users\mouazzamj058\solc_example\example.js:4:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Run Code Online (Sandbox Code Playgroud)
请帮忙.
坚固性:
function ping() public view returns ( uint ) {
return 999999999;
}
function ping2() public returns ( uint ) {
return 999999999;
}
Run Code Online (Sandbox Code Playgroud)
JavaScript Ethers.js:
(await contract.ping()).toString(); //-> 999999999 ( correct )
(await contract.ping2()).toString(); //-> [object Object] ( ?? )
Run Code Online (Sandbox Code Playgroud)
为什么 ping2 返回 [Object Object] ?如何获取 ping2 的数据?
还:
(await contract.sendTransaction(txObj)).toString(); //-> [object Object] ( ?? )
Run Code Online (Sandbox Code Playgroud)
为什么使用 sendTransaction 还返回 [object Object] ?
solidity ×10
ethereum ×8
javascript ×4
blockchain ×2
arrays ×1
composition ×1
eris ×1
ethers.js ×1
go-ethereum ×1
inheritance ×1
node.js ×1
npm ×1
oop ×1
performance ×1
struct ×1
truffle ×1
web3js ×1
websocket ×1