我创建了一个虚拟的可靠合约(https://learn.aion.network/docs/deploy-a-smart-contract-using-web3)并部署了it.The,当我尝试使用aion-web3进行呼叫时出现问题。
const contract = require('aion-web3-eth-contract');
contract.setProvider("https://aion.api.nodesmith.io/v1/mastery/jsonrpc?apiKey=*");
const Web3 = require('aion-web3');
const web3 = new Web3(new Web3.providers.HttpProvider("https://aion.api.nodesmith.io/v1/mastery/jsonrpc?apiKey=*"));
const account = web3.eth.accounts.privateKeyToAccount("****");
let myContract = new contract([...], "0xa0e1166A455a0d75CFC2bfa32D7f76f0e1852c106b981Acf59EDE327CFD36811");
// console.log("C a",myContract.options.address);
myContract.methods.getCount().call({from: account.address}, function (error, result) {
if (error){
console.log("err=>", error)
} else {
console.log("res=>", result)
}
});我希望是0,因为它是第一个调用,但它抛出了下面的错误:
TypeError: myContract.methods.getCount is not a function发布于 2019-05-24 22:43:15
看起来你试图调用这个函数的方式不太正确。尝试将约定地址放入事务对象中,然后调用该对象,而不是创建myContract对象:
let transactionCall = {
from: account.address,
to: "0xa0bf00624C2E81de745A826052D635f5c35515F0B55df6E4b1BAaCe785C124B9",
gas: 54321,
data: contractInst.methods.getCount().encodeABI()
};
web3.eth.call(transactionCall).then((res) => console.log(web3.utils.hexToNumber(res)));此外,请确保您的帐户中有硬币。这里有一个你可以使用的水龙头:https://faucets.blockxlabs.com/aion
另外,欢迎来到StackOverflow!
发布于 2019-06-12 00:05:32
尝试使用以下方法创建合同实例:
let myContract = new web3.eth.Contract(["compile contract abi info"])
和
web3.eth.call({to:YourContractAddress, data:myContract.methods.getCount().encodeABI()}).then((res) => console.log(web3.utils.hexToNumber(res)));
https://stackoverflow.com/questions/56275242
复制相似问题