以太坊警告!合同执行期间遇到错误[错误指令]或txn错误。错误的指示

时间:2019-06-24 21:41:56

标签: ethereum solidity web3js

  1. 打字稿代码:

    var openKey = appConfig.issuerAddr;
    var privateKey = appConfig.privateKey;
    
    const account = this._web3.eth.accounts.privateKeyToAccount(privateKey);
    
    this._web3.eth.accounts.wallet.add(account);
    this._web3.eth.defaultAccount = account.address;
    
    var contract = new this._web3.eth.Contract(dapp);
    this._web3.eth.getBalance("0xaFd40Ed54483A7F9E53a634312Fe8F24f344895D").then(response => console.log(response)).catch(err => console.log(err));
    
    contract.deploy({
        data: this.web3.utils.asciiToHex('dapp'),
        arguments: []
    }).estimateGas(function() {
    }).then(function(estimatedGas:any) {
            console.log(estimatedGas);
            let web3 = new Web3(appConfig.testnetAddr);
            contract.deploy({
                data: web3.utils.asciiToHex('dapp'),
                arguments: []
            }).send({
                from: openKey,
                gas: 10*estimatedGas,
                gasPrice: "3000000000"
            }, function (error:any, transactionHash:any) {
                console.log(error, transactionHash);
            }).on('error', function (error:any) {
                console.log('error', error);
            }).on('false', function(error:any) {
                console.log(error);
            }).on('transactionHash', function (transactionHash:any) {
                console.log('transactionHash', transactionHash);
            }).on('receipt', function (receipt:any) {
                console.log('receipt', receipt.contractAddress);
            }).on('confirmation', function (confirmationNumber:any, receipt:any) {
                console.log('confirmation', confirmationNumber);
            }).catch(err => console.log(err, 'test'));
    
    }).catch(function(err) {
        console.log(err)
    });
    
  2. ABI:

    export const dapp = [ {     “恒定”:是的,     “输入”:[],     “ name”:“ get”,     “输出”:[         {             “名称”: ””,             “ type”:“地址”         }     ],     “应付”:假,     “ stateMutability”:“视图”,     “ type”:“功能” }, {     “输入”:[],     “应付”:假,     “ stateMutability”:“不可支付”,     “ type”:“构造函数” } ];

  3. 合同(sol):

    pragma solidity ^ 0.5.1;

    合约dapp { 地址所有者;

    constructor()公共{     所有者= msg.sender; }

    function get()公共视图返回(地址){     归还所有者; } }

0 个答案:

没有答案