![](/img/trans.png)
[英]I get “Invalid Webhook Token” error while following up an interaction
[英]I get this the error "Error: invalid address ...." while running my dapp
我正在為我的私有區塊鏈 Quorum 開發一個簡單的 dapp。 我用 Solidity 寫了智能合約,用 JavaScript 寫了一個腳本。
在運行我的區塊鏈和 JavaScript 控制台后,我執行了以下操作:
我得到錯誤:
錯誤:地址無效
在 web3.js:3930:15
在 web3.js:3756:20
在 web3.js:5025:28
在地圖(<本機代碼>)
在 web3.js:5024:12
在 web3.js:5050:18
在 web3.js:5075:23
在 web3.js:4137:16
我的智能合約是這樣的:
pragma solidity >=0.4.0 <0.7.5;
contract MyContract {
int value;
constructor() public{
value=10;
}
function get() public view returns(int) {
return value;
}
function set(int value2) public {
value=value2;
}
}
我在 javascript 中的腳本是這樣的:
a = eth.accounts[0]
web3.eth.defaultAccount = a;
// Risultato del comando > solcjs --bin --abi MyContract.sol
var abi = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"get","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"value2","type":"int256"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"}];
var bytecode = "0x60806040523480156100115760006000fd5b505b600a60006000508190909055505b610026565b60db806100346000396000f3fe608060405234801560105760006000fd5b506004361060365760003560e01c80636d4ce63c14603c578063e5c19b2d146058576036565b60006000fd5b60426084565b6040518082815260200191505060405180910390f35b608260048036036020811015606d5760006000fd5b81019080803590602001909291905050506095565b005b600060006000505490506092565b90565b8060006000508190909055505b5056fea264697066735822122032710d493b7bc22bd80599320435533d8a94bf485e2b4c09f9ba2b0dd44acb4964736f6c63430007040033";
// Creazione del nuovo contratto con nome MyContract
var simpleContract = web3.eth.contract(abi);
var simple = simpleContract.new({from:web3.eth.accounts[0], data: bytecode, gas: 0x47b760, privateFor: ["QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc="]}, function(e, contract) {
if (e) {
console.log("Error creating contract", e);
} else {
if (!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
});
我可以嘗試什么來解決這個問題?
我認為問題在於您在 ABI 中有一個小錯誤 - 由於該函數被標記為view
所以get()
函數在 abi 中應該有"constant":true
。
如果沒有,則get()
函數需要一個from
地址事務被定義(即你必須使用private.get({"from": fromAddress})
或使用設置默認帳戶web3.eth.defaultAccount = accountAddress
) .
如果您更正 ABI,那么它應該可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.