下面的代码仅返回收据,但我希望它返回一个数据元组,如下面的合同所示。我如何让它返回数据?我找不到关于如何保存和检索数据的好教程。我知道这是一个昂贵的用例,我只是想做一个基本的概念证明并同时学习。
我正在使用 web3@1.0.0-beta.29
export class AppComponent {
  title = 'app';
  dappUrl: string = 'http://myapp.com';
  web3: any;
  contractHash: string = '0x3b8a60616bde6f6d251e807695900f31ab12ce1a';
  MyContract: any;
  contract: any;
  ABI: any = [{"constant":true,"inputs":[{"name":"idx","type":"uint256"}],"name":"getLocationHistory","outputs":[{"name":"delegate","type":"address"},{"name":"longitude","type":"uint128"},{"name":"latitude","type":"uint128"},{"name":"name","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"recentLocation","outputs":[{"name":"delegate","type":"address"},{"name":"longitude","type":"uint128"},{"name":"latitude","type":"uint128"},{"name":"name","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"longitude","type":"uint128"},{"name":"latitude","type":"uint128"},{"name":"name","type":"bytes32"}],"name":"saveLocation","outputs":[],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"getLastLocation","outputs":[{"components":[{"name":"delegate","type":"address"},{"name":"longitude","type":"uint128"},{"name":"latitude","type":"uint128"},{"name":"name","type":"bytes32"}],"name":"recentLocation","type":"tuple"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"locations","outputs":[{"name":"delegate","type":"address"},{"name":"longitude","type":"uint128"},{"name":"latitude","type":"uint128"},{"name":"name","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"item","outputs":[{"name":"id","type":"bytes32"},{"name":"name","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"id","type":"bytes32"},{"name":"name","type":"bytes32"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}];
  constructor(private route: ActivatedRoute) { }
  @HostListener('window:load')
  windowLoaded() {
    this.checkAndInstantiateWeb3();
    this.getLocation();
  }
  getLocationHistory() {
    this.MyContract.methods
      .getLocationHistory(0).send({
      'from': '0x902D578B7E7866FaE71b3AB0354C9606631bCe03',
      'gas': '44000'
    }).then((result) => {
      this.MyContract.methods.getLocationHistory(0).call()
        .then(hello => {console.log('hello', hello)});
    });
  }
  private checkAndInstantiateWeb3 = () => {
    if (typeof window.web3 !== 'undefined') {
      console.warn('Using web3 detected from external source.');
      // Use Mist/MetaMask's provider
      this.web3 …以下是我的智能合约.当我把它放入混音时,我会收到以下每个功能的警告.
函数GasRecord.addNote(bytes32,bytes32)的气体要求高:无限.
函数GasRecord.getDoctorsNames()的气体要求高:无限.
函数GasRecord.getNotes()的气体要求高:无限.
函数GasRecord.giveDoctorAccess(address,bytes32)的气体要求高:无限.
pragma solidity ^0.4.17;
contract MedicalRecord {
struct Doctor {
    bytes32 name;
    uint id;
}
struct Note {
    bytes32 title;
    bytes32 note;
}
address public patient;
uint private doctorId;
bytes32[] public doctorsNames;
Note[] notes;
mapping (address => Doctor) private doctors;
modifier onlypatient {
    require(msg.sender == patient);
    _;
}
modifier isCurrentDoctor {
    require(!(doctors[msg.sender].id < doctorId));
    _;
}
function MedicalRecord() public {
    patient = msg.sender;
    doctorId = 0;
}
function giveDoctorAccess(address drAddress, bytes32 name)
public
onlypatient
returns (bytes32) …在过去的几天里,我一直在尝试在以太坊测试网 Rinkeby 上发送一笔交易,无论我将 Gas 增加多少,都会不断收到此错误。
“未处理的拒绝错误:返回错误:内在气体太低”
我发送的数据是:
"0x7b22416e7377657273223a5b7b225175657374696f6e223a2231222c22416e73776572223a2234227d2c7b225175657374696f6e223a2232222c22416e73776572223a2234227d2c7b225175657374696f6e223a2233222c22416e73776572223a2234227d2c7b225175657374696f6e223a2234222c22416e73776572223a2234227d2c7b225175657374696f6e223a2235222c22416e73776572223a2234227d2c7b225175657374696f6e223a2236222c22416e73776572223a2234227d5d7d"
转换为十六进制后。
我在下面添加了我的代码。
"0x7b22416e7377657273223a5b7b225175657374696f6e223a2231222c22416e73776572223a2234227d2c7b225175657374696f6e223a2232222c22416e73776572223a2234227d2c7b225175657374696f6e223a2233222c22416e73776572223a2234227d2c7b225175657374696f6e223a2234222c22416e73776572223a2234227d2c7b225175657374696f6e223a2235222c22416e73776572223a2234227d2c7b225175657374696f6e223a2236222c22416e73776572223a2234227d5d7d"
我想获取用户在 Metamask 中添加的所有帐户。我尝试了所有 web3.js 方法来获取帐户,但我总是只得到一个帐户,并且始终是当前选择的帐户。
根据 web3.js 文档,web3.eth.getAccounts()应该返回该节点控制的所有帐户。但是,我得到了一个仅包含当前选定数组的数组。不用说,我在 Metamask 中创建了多个帐户。
我尝试遵循此repo :-
但是我在编译代码时遇到以下错误:-
code = fs.readFileSync('Voting.sol').toString()
solc = require('solc')
compiledCode = solc.compile(code)
它抛出了这个错误:-
'{"errors":[{"component":"general","formattedMessage":"* Line 1, Column 1\\n  Syntax error: value, object or array expected.\\n* Line 1, Column 2\\n  Extra non-whitespace after JSON value.\\n","message":"* Line 1, Column 1\\n  Syntax error: value, object or array expected.\\n* Line 1, Column 2\\n  Extra non-whitespace after JSON value.\\n","severity":"error","type":"JSONError"}]}'
我在从 web3js 传递(javascript 对象数组)到以(结构数组)作为参数的solidity 函数时遇到错误。
你可以帮帮我吗?
下面是代码和错误
// web3js code
let slctedItems = [{name:'item1', qty:2},{name:'item2', qty:3}];
contract.methods.calcItems(slctedItems).call((err, total) => {
      // code
    })
//solidity code
 struct Item{
        string name;
        uint qty;
    }
function calcItems(Item[] memory _items) public view returns(uint){
        //code 
       // return uint
    }
//solidity code
 struct Item{
        string name;
        uint qty;
    }
function calcItems(Item[] memory _items) public view returns(uint){
        //code 
       // return uint
    }
问题的在线示例和我编写的代码。在下面的链接中:https : 
//malaak-habashy.github.io/
我在 web3js github 上发现了一个问题。请参阅以下链接:https : 
//github.com/ethereum/web3.js/issues/3538
我正在尝试开始使用 Angular 和 Web3.js 来处理一些以太坊合约。重现:
包.json:
{
  "name": "ng-eth",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~11.0.6",
    "@angular/common": "~11.0.6",
    "@angular/compiler": "~11.0.6",
    "@angular/core": "~11.0.6",
    "@angular/forms": "~11.0.6",
    "@angular/platform-browser": "~11.0.6",
    "@angular/platform-browser-dynamic": "~11.0.6",
    "@angular/router": "~11.0.6",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "web3": "^1.3.4",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1100.6",
    "@angular/cli": "~11.0.6",
    "@angular/compiler-cli": "~11.0.6",
    "@types/jasmine": "~3.6.0",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0", …我希望能够找出从部署到现在的 RDOC 交易总量。
无法从区块浏览器获取此信息:
0x2d919f19d4892381d58edebeca66d5642cef1a1f
使用 RPC 或 web3.js 获得它的最佳方法是什么?
我尝试通过执行以下操作使用 node.js 安装 web3 npm install web3 --save,但是当我检查node_modules/文件夹时,任何地方都没有dist文件夹及其web3.min.js文件。关于如何或为什么的任何想法?
我想使用提供者配置我的 truffle-config.js。当我运行命令“truffle migrate --network ropsten”时,它会抛出以下错误:
错误:Web3ProviderEngine 不支持同步请求。
并告诉了错误详细信息
at Object.run (C:\Users\Bruce\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:92:1)
我对此一无所知。我查找文件
"C:\Users\Bruce\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:92:1"webpack ,但我找不到下面的路径这"build/"。是不是出了什么问题?我使用 global 安装 truffle,它在默认网络 ganache 下运行良好。
ropsten: {
      provider: () => new HDWalletProvider(
        privateKeys.split(','),
        `https://ropsten.infura.io/v3/${process.env.INFURA_API_KEY}`
      ),
      network_id: 3,       // Ropsten's id, mainnet is 1
      gas: 5500000,        // Ropsten has a lower block limit than mainnet
      gasPrice: 2500000000, //2.5 gwei
      confirmations: 2,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50) …