错误:方法eth_sendTransaction不存在/不可用

问题描述 投票:0回答:1

在调用solid实现合同时显示错误,该合同已在ropsten-infura中部署。我正在使用web3(@ 0.19.1)来调用合同。

有人遇到同样的问题吗?

node.js blockchain ethereum solidity web3js
1个回答
0
投票

我猜你直接连接到Infura,它不支持eth_sendTransaction。 (为了支持它,它需要知道你的私钥,但它是一个共享的公共节点。)

您需要自己签署事务,然后通过eth_sendRawTransaction发送或使用可以在浏览器中保存MetaMask等私钥的提供程序。


0
投票

您需要先签署交易,这就是我使用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'));
        }
    });
}

你可以在这里看到完整的代码https://github.com/SelfKeyFoundation/Identity-Wallet/blob/60733b208275119b31abf2cb3ab1f49f0b6801a3/src/main/blockchain/web3-service.js#L42-L76

© www.soinside.com 2019 - 2024. All rights reserved.