簡體   English   中英

寫入以太坊wiithout元掩碼

[英]Write to ethereum wiithout metamask

我試圖在不使用元掩碼的情況下向Ethereum Rinkeby測試網絡寫入一些數據,但是在調用該方法時出現以下錯誤,但是我的參數計數是正確的

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 246): Error: Invalid number of arguments to Solidity function

節點代碼

    var Web3        = require('web3')
    var contract    = require("truffle-contract")
    var quickBooks    = require('../build/contracts/quickBooks.json')

    Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send;

    var provider    = new Web3.providers.HttpProvider("https://rinkeby.infura.io/v3/KEY")
    var quickBooksContract = contract(quickBooks);
    quickBooksContract.setProvider(provider);


    var writeToEthereum = async function(_json){
        //console.log(_json)
        var instance = await quickBooksContract.at('ADDRESS')
        var result = await instance.write.call(_json,_json.txhash,_json.createdt,"1",_json.write_set[0].set,{
from : "ADDRESS"
})
        console.log(result);
    }

堅固性

實用實驗性ABIEncoderV2;

合約quickBooks {

struct Tx{
    string txId;
    string timeStamp;
    string blockHash;
    string payLoad;
    string json;
}

mapping(string => Tx) private data;

function write(string _json,string _txId,string _timeStamp,string _blockHash,string _payLoad) public returns(bool success){
    data[_txId] = Tx(_txId,_timeStamp,_blockHash,_payLoad,_json);
    return true;
}

function read(string _txId)public returns(Tx){
    return data[_txId];
} 

}

這可能與https://github.com/ethereum/web3.js/issues/1043有關

查看那里的討論。

如果您正在使用松露,請嘗試:

伙計們,刪除您的構建文件夾,然后運行命令。

 npm run truffle migrate --reset --compile-all 

我發現,在本地(而非全局)對文件夾運行松露時,效果最好,這是因為Beta和不同版本最近得到了快速更新。 如果您更喜歡全局方法,請嘗試

 truffle migrate --reset --compile-all 

如果這樣做沒有幫助,請確保提供正確的數據類型 可能是您提供的是字符串而不是int。

如果這還沒有幫助,我將需要更多有關您使用的Web3版本以及是否使用松露以及版本的信息。

如果您想了解有關Solidity和智能合約創建的更多信息,請查看我專門為此做的課程-Solidity Smart Contracts:在以太坊區塊鏈中構建Dapps

這是折價券: QAUS8657

call的合同函數錯誤,應在函數名稱后將參數傳遞給函數。 執行此操作的方式是將參數傳遞到call()選項的位置。

await instance.write(<params here>).call();

您可以在文檔上閱讀有關此內容的更多信息: https : //web3js.readthedocs.io/en/1.0/web3-eth-contract.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM