在调用solid实现合同时显示错误,该合同已在ropsten-infura中部署。我正在使用web3(@ 0.19.1)来调用合同。
有人遇到同样的问题吗?
我猜你直接连接到Infura,它不支持eth_sendTransaction
。 (为了支持它,它需要知道你的私钥,但它是一个共享的公共节点。)
您需要自己签署事务,然后通过eth_sendRawTransaction
发送或使用可以在浏览器中保存MetaMask等私钥的提供程序。
您需要先签署交易,这就是我使用web3 1.0.0的方式。
我使用了MetaMask的web3-provider-engine:https://github.com/MetaMask/web3-provider-engine/blob/master/subproviders/hooked-wallet-ethtx.js
getWalletEthTxSubprovider() {
return new HookedWalletEthTxSubprovider({
getAccounts: callback => {
callback(null, [this.web3.eth.defaultAccount]);
},
getPrivateKey: (address, callback) => {
if (address.toLowerCase() === this.web3.eth.defaultAccount.toLowerCase()) {
return callback(
null,
Buffer.from(
this.web3.eth.accounts.wallet[address].privateKey.replace('0x', ''),
'hex'
)
);
}
return callback(new Error('not private key supplied for that account'));
}
});
}