I'm developing a simple dapp for my private blockchain Quorum. I wrote my smart contract in Solidity and a script with JavaScript.
After running my blockchain and my JavaScript console, I did this:
and I get the error:
Error: invalid address
at web3.js:3930:15
at web3.js:3756:20
at web3.js:5025:28
at map ( < native code > )
at web3.js:5024:12
at web3.js:5050:18
at web3.js:5075:23
at web3.js:4137:16
My smart contract is this one:
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;
}
}
And my script in javascript is this one:
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);
}
}
});
What can I try to resolve this?
I think the issue is that you have a small mistake in the ABI - the get()
function should have "constant":true
in the abi due to the function being labelled as view
.
Without that, the get()
function requires a from
address to be defined for the transaction (ie you have to use private.get({"from": fromAddress})
or set the default account using web3.eth.defaultAccount = accountAddress
).
If you correct the ABI then it should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.