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. Android handler 详解(面试百分之100问到)

    handler在Android中被称为“消息处理者”,在多线程中比较常用. handler内部实现原理 handler实现机制:1,Message对象,表示要传递的一个消息,内部使用链表数据结构实现一 ...

  2. EasyDropDown – 很棒的下拉菜单 含精美主题

    EasyDropDown 是一个 jQuery 插件,你可以毫不费力地将简陋的 Select 元素设置为可定制风格的下拉菜单,用于表单或者一般的导航.和著名的下拉插件 Chosen 很像,但是具有自己 ...

  3. tyvj1017 - 冗余关系 ——并查集

    题目链接:https://www.tyvj.cn/Problem_Show.aspx?id=1017 并查集 #include <cstdio> #include <cstdlib& ...

  4. 事务报错 [Exception] 当前 TransactionScope 已完成

    捕获异常的时候 偶尔会碰到这个异常报告 导致原因 //正确代码 using (TransactionScope ts = new TransactionScope(TransactionScopeOp ...

  5. Bootstrap 组件之 Navbar

    一.简介 Navbar 指导航条,它在移动设备上显示为折叠状态,在宽屏幕上水平展开.这里 是一个线上例子. 响应式导航条依赖 collapse 插件,定制 Bootstrap 时务必要包含. {设备的 ...

  6. Manjaro kde 18.0安装与基本配置

    目录 更换源镜像.更新系统 安装搜狗输入法 安装软件 系统配置 最后清理垃圾 首先用Rufus制作启动U盘安装,设置好时间和日期等 更换源镜像.更新系统 排列源(只选清华源mirrors.tuna.t ...

  7. Mysql 之闪回技术 binlog2sql

    1.下载 https://github.com/danfengcao/binlog2sql http://rpmfind.net Search: python-pip pip 是一个Python包管理 ...

  8. 解决php中文乱码

    在文件的第一行,加入下面这一句: header("Content-Type: text/html; charset=utf8"); 然后在把文件以utf-8的格式保存起来就行了

  9. 在Spring Boot中使用 @ConfigurationProperties 注解 (二十六)

    @ConfigurationProperties主要作用:就是绑定application.properties中的属性 java代码 @Configuration public class DataS ...

  10. 51nod 1962区间计数(单调栈加二分)

    题目要求是求出两个序列中处于相同位置区间并且最大值相同的区间个数,我们最直观的感受就是求出每个区间的最大值,这个可以O(N)的求,利用单调栈求出每个数作为最大值能够覆盖的区间. 然后我们可以在进行单调 ...