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. ADs系列之通用数据解析服务GAS(即将开源)

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

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

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

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

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

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

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

  5. [LeetCode] Gas Station

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

  6. 20. Candy && Gas Station

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

  7. Gas Station [LeetCode]

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

  8. 134. Gas Station

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

  9. [LeetCode OJ] Gas Station

    问题描述: There are N gas stations along a circular route, where the amount of gas at station i is gas[i ...

随机推荐

  1. SVG坐标系统

    SVG的画布.画布视区(viewBox).浏览器视窗的概念 画布 画布是绘制SVG内容的一块区域,理论上在所有维度上都是无限的.(也有人称为"SVG世界",但我觉得叫画布比较合适) ...

  2. jQuery对数据和对象的操作

    <script type="text/javascript" src="jquery-1.8.2.min.js"></script> & ...

  3. span 与p 的区别,以及内联元素的作用

    1.一般标签都有语义,p标签是指一个段落,而且默认是一个块级元素,span是一个行内元素的代表,没有什么意思,一般可以放文字等行内元素,例如<p>这是一段简介内容这是一段 <span ...

  4. Spring使用——环境部署和配置问题总结

    众所周知,spring是Java中一个非常非常重要的框架,主要提供了依赖注入DI,和切面编程AOP.我多年前做过一段时间的Java,不过那时候项目中没有用Spring,所以一直也没有特别注意,最近看了 ...

  5. 【转】Linux下nginx配置https协议访问的方法

    一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...

  6. Appium查找元素

    记录一些需要记忆的查找元素的内容: 1. driver.findElement(By.name("DELETE");   //We can use the DELETE text ...

  7. Kali Rolling在虚拟机安装后的设置

    Kali Linux在2016年的第一个发行版——Kali Rolling是Debian的即时更新版,只要Debian中有更新,更新包就会放入Kali Rolling中,供用户下载使用.它为用户提供了 ...

  8. FileUpload类别FileUpload1.FileName和FileUpload1.PostedFile.FileName差异

    FileUpload1.FileName 用来获取client上使用 FileUpload 控件上载的文件的名称.此属性返回的文件名称不包括此文件在client上的路径. FileUpload1.Po ...

  9. MYSQL:RELPACE用法

    RELPACE类似于INSERT的方法,但如果表中的旧行与主键或惟一索引的新行具有相同的值,则在插入新行之前删除旧行 为了测试方便我们首先要创建一张表 CREATE TABLE test ( id I ...

  10. UML建模之时序图(Sequence Diagram)

    一.时序图简介(Brief introduction) 二.时序图元素(Sequence Diagram Elements) 角色(Actor) 对象(Object) 生命线(Lifeline) 控制 ...