1.昨天遇见了还是以前遇见的问题,就是发现有些函数就是不能用web3调用,然后怎么弄都写不到数组上,但是今天终于将它解决了
web3的学习:
https://github.com/ethereum/wiki/wiki/JavaScript-API

今天又重新想要跑一下cryptopunks
当想要在私有链配置自己的合约的时候,有时你会很残酷地发现它告诉你out of gas,这个时候你就要去查看你的初始块配置的时候的gasLimit是不是设的比较小了,或者是你部署合约的时候gas给的是不是太小
重新又创建了一个私有链local4,这一次它的gaslimit设置为8个f,果然就没有再出现过gas方面的问题了

但是在调用函数的时候我又出现了gas方面的问题

我发现这个问题的原因竟然是因为我调用的时候没有设定使用的gas数,在remix的compile-details-gasestimates中我们是可以查看到每个函数大概要用到的gas的数量的,在下面的错误的transaction信息中,我们可以看见,gas的估计基本上都是90000,我想啊,这可能是自定义的每一个函数使用的最大值,当你的函数运行超过这个值以后呢,可能运行就不成功了,因为没gas了,所以之前的调用才会出错
然后之后我就去测了一个没有设置gas但是成功了的transaction,然后发现它的gas值处果然是90000,这个值是该交易的sender给的gas数

> eth.getTransaction('0x4650e6c26f9ad2b850b66ad0e2b6836f4e6ad1760453d45c9d5d870c312cc227')
{
blockHash: "0x40afdacfe0d91bac521ae4ff924b00952191da1d201180c31e6b368b83f25f06",
blockNumber: 132,
from: "0x0c585ae7e2e15ffd3e04e82c0e4adf5bad5a94b0",
gas: 90000,
gasPrice: 18000000000,
hash: "0x4650e6c26f9ad2b850b66ad0e2b6836f4e6ad1760453d45c9d5d870c312cc227",
input: "0x3ccfd60b",
nonce: 13,
r: "0x8af9e5b6be338538c2862bb36516052c9782a819644acea94cff243cbc2dab82",
s: "0x63e5f39801860647e82ebd736fa1c32dc00fb2d53b58f55fac87c46e87bf3501",
to: "0xafddc17c7963bd81598defbe28b43230a4bdb719",
transactionIndex: 0,
v: "0x41",
value: 0
}

然后再去查看一个自己设置了gas的transaction的gas值,我们可以很明确地看见这里的gas值就是我自己设置的300000

> eth.getTransaction('0x97a1ea29b42e0c7edee7fcfb742920b18c2732ee1a3e33ff2371a5208a13ca1e')
{
blockHash: "0xe1c7fe5cd751935f98a6fc0d3b65eab9ac4b1f4b5dcc81bbdcaf258aa40f4f26",
blockNumber: 131,
from: "0x0c585ae7e2e15ffd3e04e82c0e4adf5bad5a94b0",
gas: 300000,
gasPrice: 18000000000,
hash: "0x97a1ea29b42e0c7edee7fcfb742920b18c2732ee1a3e33ff2371a5208a13ca1e",
input: "0x23165b7500000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000258",
nonce: 12,//交易的发起者在之前进行过的交易数量。
r: "0x771a755550958a5863d8ca5b56784d62fa449afb724fd2efd28bd36a38dc183a",
s: "0x2fc49b6f4303fe4beb96f70921ca79100ac3a991206132429aa4e42e45590bad",
to: "0xafddc17c7963bd81598defbe28b43230a4bdb719",
transactionIndex: 0,//该交易在区块中的索引
v: "0x41",
value: 0
}

Web3调用语句:

instance.acceptBidForPunk(6,600,{from:web3.eth.accounts[1]});
> eth.getTransactionReceipt('0x2cab683a0c84d917210652f18f80161e8141893497e45cd09609525d537ad86e')
{
blockHash: "0x15d1f2d37f4647419dc583d1af1dd47d183e8c21041254b07e9f8ea7ff81f496",
blockNumber: 128,
contractAddress: null,
cumulativeGasUsed: 90000,
from: "0x0c585ae7e2e15ffd3e04e82c0e4adf5bad5a94b0",
gasUsed: 90000,
logs: [],
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
status: "0x0",//没成功
to: "0xafddc17c7963bd81598defbe28b43230a4bdb719",
transactionHash: "0x2cab683a0c84d917210652f18f80161e8141893497e45cd09609525d537ad86e",
transactionIndex: 0
}

从这个返回结果我们可以看出这笔交易没能成功写到区块上

本来这个函数的作用是接受这个投标bid,然后下面来个数组的信息就应该变为false等,但是可以看见下面的输出还是没有改变
console.log(instance.punksOfferedForSale.call(6));
console.log(instance.punkBids.call(6));

[ true,
BigNumber { s: 1, e: 0, c: [ 6 ] },
'0x0c585ae7e2e15ffd3e04e82c0e4adf5bad5a94b0',
BigNumber { s: 1, e: 2, c: [ 600 ] },
'0x0000000000000000000000000000000000000000' ]
wanghuideMacBook-Pro:new wanghui$ node new1.js
wanghuideMacBook-Pro:new wanghui$ node new1.js
[ true,
BigNumber { s: 1, e: 0, c: [ 6 ] },
'0xa79be9d7cb24c4b43f5e89198f25a96f7a5f191f',
BigNumber { s: 1, e: 2, c: [ 620 ] } ]

Web3调用语句,加上gas后:
instance.acceptBidForPunk(6,600,{from:web3.eth.accounts[1],gas:300000});

> eth.getTransactionReceipt('0x97a1ea29b42e0c7edee7fcfb742920b18c2732ee1a3e33ff2371a5208a13ca1e')
{
blockHash: "0xe1c7fe5cd751935f98a6fc0d3b65eab9ac4b1f4b5dcc81bbdcaf258aa40f4f26",
blockNumber: 131,
contractAddress: null,
cumulativeGasUsed: 56074,
from: "0x0c585ae7e2e15ffd3e04e82c0e4adf5bad5a94b0",
gasUsed: 56074,
logs: [{
address: "0xafddc17c7963bd81598defbe28b43230a4bdb719",
blockHash: "0xe1c7fe5cd751935f98a6fc0d3b65eab9ac4b1f4b5dcc81bbdcaf258aa40f4f26",
blockNumber: 131,
data: "0x0000000000000000000000000000000000000000000000000000000000000001",
logIndex: 0,
removed: false,
topics: ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", "0x0000000000000000000000000c585ae7e2e15ffd3e04e82c0e4adf5bad5a94b0", "0x000000000000000000000000a79be9d7cb24c4b43f5e89198f25a96f7a5f191f"],
transactionHash: "0x97a1ea29b42e0c7edee7fcfb742920b18c2732ee1a3e33ff2371a5208a13ca1e",
transactionIndex: 0
}, {
address: "0xafddc17c7963bd81598defbe28b43230a4bdb719",
blockHash: "0xe1c7fe5cd751935f98a6fc0d3b65eab9ac4b1f4b5dcc81bbdcaf258aa40f4f26",
blockNumber: 131,
data: "0x0000000000000000000000000000000000000000000000000000000000000000",
logIndex: 1,
removed: false,
topics: ["0x58e5d5a525e3b40bc15abaa38b5882678db1ee68befd2f60bafe3a7fd06db9e3", "0x0000000000000000000000000000000000000000000000000000000000000006", "0x0000000000000000000000000c585ae7e2e15ffd3e04e82c0e4adf5bad5a94b0", "0x0000000000000000000000000000000000000000000000000000000000000000"],
transactionHash: "0x97a1ea29b42e0c7edee7fcfb742920b18c2732ee1a3e33ff2371a5208a13ca1e",
transactionIndex: 0
}],
logsBloom: "0x00000000004000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000400000000000000000000000000000100010000000008000000000000000000000000000000001000000000000000020000000000000000000800000000000000000000000010000000000000000408000000001000400000000000000000000008000000800000000000000000000000000000000000000000000000000000000000000000080000000000000002000000000000000000000000000000000000000000000000000020000000000080000000000000000000000000000000000000000000002000000000",
status: "0x1",
to: "0xafddc17c7963bd81598defbe28b43230a4bdb719",
transactionHash: "0x97a1ea29b42e0c7edee7fcfb742920b18c2732ee1a3e33ff2371a5208a13ca1e",
transactionIndex: 0
}

然后就发现这个函数的调用成功了,但是很奇怪的一点,就是我们可以从gasUsed: 56074看出,真正使用到的gas其实是小于90000的,但是为什么还是失败,之后看见在解释吧
数组信息变为:
console.log(instance.punksOfferedForSale.call(6));
console.log(instance.punkBids.call(6));

[ false,
BigNumber { s: 1, e: 0, c: [ 6 ] },
'0xa79be9d7cb24c4b43f5e89198f25a96f7a5f191f',
BigNumber { s: 1, e: 0, c: [ 0 ] },
'0x0000000000000000000000000000000000000000' ]
[ false,
BigNumber { s: 1, e: 0, c: [ 6 ] },
'0x0000000000000000000000000000000000000000',
BigNumber { s: 1, e: 0, c: [ 0 ] } ]

余额变为
console.log(instance.pendingWithdrawals.call(web3.eth.accounts[1]));

BigNumber { s: 1, e: 2, c: [ 620 ] }

当然,这上面只是十分死板地将gas的值给定死了,如果想要比较自动得到使用的gas值的话,是可以使用web3的estimate来做的
或者是你可以先调用一个函数,但是这个时候你还不要进行挖矿,然后此时交易的区块的状态就是pending,查看其gaslimit
web3.eth.getBlock("pending").gasLimit
4712388

然后在gas处就可以写这个值了

gas问题out of gas的解决的更多相关文章

  1. solidity 合约单元测试报错 org.fisco.bcos.web3j.protocol.exceptions.TransactionException: Transaction has failed with status: 0x16. Gas used: 1163650. (not-enough gas?)

    org.fisco.bcos.web3j.protocol.exceptions.TransactionException: Transaction has failed with status: 0 ...

  2. ADs系列之通用数据解析服务GAS(即将开源)

    面对成百上千的生产系统用户操作数据接入落地,你是否厌倦了每次机械编写打包解包的代码?对一次性接入多个数据的时候,还要对不同人联调,费时费力,你是否还会手忙脚乱,忙中不断出错?是否当数据出问题了,用的时 ...

  3. Self-organizing Maps及其改进算法Neural gas聚类在异常进程事件识别可行性初探

    catalogue . SOM简介 . SOM模型在应用中的设计细节 . SOM功能分析 . Self-Organizing Maps with TensorFlow . SOM在异常进程事件中自动分 ...

  4. 区块链扩容方案之Gas值限制

    区块链扩容一直是区块链团队的重点研究方向.因为比特币对区块大小的设定是固定的,而且中本聪将最初大小值限定为1M,但随着交易量的增加,网络拥堵情况也愈渐严重,最终也导致了比特币的分叉. 区别于比特币固定 ...

  5. 【LeetCode】Gas Station 解题报告

    [LeetCode]Gas Station 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/gas-station/#/descr ...

  6. [LeetCode] Gas Station 加油站问题

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  7. [LeetCode] Gas Station

    Recording my thought on the go might be fun when I check back later, so this kinda blog has no inten ...

  8. 20. Candy && Gas Station

    Candy There are N children standing in a line. Each child is assigned a rating value. You are giving ...

  9. Gas Station

    Description: There are N gas stations along a circular route, where the amount of gas at station i i ...

随机推荐

  1. LINQ分页和排序,skip和Take 用法

    LINQ分页和排序,skip和Take 用法 dbconn.BidRecord.OrderBy(p=>p.bid_id).ToList<BidRecord>().OrderBy(p ...

  2. jquery中innerwidth,outerwidth,outerwidth和width的区别

    在jQuery中,width()方法用于获得元素宽度: innerWidth()方法用于获得包括内边界(padding)的元素宽度, outerWidth()方法用于获得包括内边界(padding)和 ...

  3. java根据年月显示每周

    一.页面效果 1.展示7月份的所有周. 2.当前时间2018.08.02  ,  显示到本周. 二.前端代码 1.显示层的代码 <span id="weekyear"> ...

  4. springMVC 拦截器源码解析

    前言:这两天学习了代理模式,自然想到了 springmvc 的 aop 使用的就是动态代理,拦截器使用的就是 jdk 的动态代理.今天看了看源码,记录一下.转载请注明出处:https://www.cn ...

  5. hadoop的企业优化

    前言: Mapreduce程序的效率的瓶颈在于两点: 计算机性能: CPU.内存.磁盘健康.网络 I/O操作: 数据倾斜 map和reduce数量设置不合理 map的运行时间太长,导致reduc的等待 ...

  6. MySQL and Sql Server:Getting metadata using sql script (SQL-92 standard)

    MySQL: use sakila; -- show fields from table_name; -- show keys from table_name; SELECT `REFERENCED_ ...

  7. UED与UCD

    UED User Experience Design(用户体验设计),简称UED.UED是以用户为中心的一种设计手段,以用户需求为目标而进行的设计.设计过程注重以用户为中心,用户体验的概念从开发的最早 ...

  8. 洛谷P4719 【模板】动态dp(ddp LCT)

    题意 题目链接 Sol 动态dp板子题.有些细节还没搞懂,待我研究明白后再补题解... #include<bits/stdc++.h> #define LL long long using ...

  9. 虚拟机安装ubuntu18.04及其srs服务器的搭建

    第一次写博客,有些地方可能不太完善. 1.安装VMware,我用的是VMware12. 2.下载Ubuntu镜像(自Ubuntu 17.10开始桌面版本不再提供32位安装镜像,Ubuntu Serve ...

  10. 【读书笔记】iOS-解析XML

    使用最广泛的解析XML文档的方法有两种,一种基于SAX,另一种基于DOM.SAX解析器是事件驱动型的,在解析时增量地读取XML文档,当解析器识别出一个结点的时候会调用相应的委托方法. 参考资料< ...