Closed mqklin closed 5 years ago
Are you running it in a browser with bundling it first?
Yep, bundling with webpack. I can create a repro repo if it's needed
I don't know how but it is fixed now =/ Sorry for the troubling and thanks for the response
No, it's not fixed. I'll provide the repro this week
Great thanks!:)
Repro: https://github.com/mqklin/web3-test
I found the problem, it's because of @0x/subproviders
package. It is strange that I don't even import
it into my project, only install with yarn
, and that's enough to trigger this error.
I have to use this package because I need to use HTTP provider (Alchemy in my case), but let user to sign transactions with custom provider (MetaMask, Status, Fortmatic, etc).
@nivida could you please help me, how can I do this without @0x/subproviders
?
I tried to do this: web3.eth.transactionSigner = new web3.eth.transactionSigner.constructor({sign: window.web3.sign});
but it throws 'Invalid TransactionSigner given!'
.
Is transactionSigner
not implemented yet?
Feel free to close the issue, because as I can understand it's related to that package, and not to web3.js
.
@mqklin
Example of the usage of a custom TransactionSigner
:
const options {
transactionSigner: new CustomSigner();
};
const web3 = new Web3(provider, null, options);
The CustomSigner
has to provide the following interface:
interface TransactionSigner {
sign(txObject: Transaction): Promise<SignedTransaction>
}
interface SignedTransaction {
messageHash: string,
v: string,
r: string,
s: string,
rawTransaction: string
}
Feel free to create a new issue here if the issue in the subproviders
repository of 0x gets closed.
const keyPair = {
publicKey: process.env.GANACHE_PUB,
privateKey: Buffer.from(process.env.GANACHE_PRI, 'hex'),
};
this.contractInstance = new this.web3.eth.Contract(TrueGrailToken.abi, '0x833bbEd979314708B071C672E213484024D11fd8');
console.log(this.contractInstance.methods.tokenMetadata(211014440472470).encodeABI());
const options = {
from: keyPair.publicKey,
to: '0x833bbEd979314708B071C672E213484024D11fd8',
data: this.contractInstance.methods.tokenMetadata(211014440472470).encodeABI(),
gasPrice: 3000,
gasLimit: 250000,
nonce: 1000,
};
const tx = new Tx(options);
tx.sign(keyPair.privateKey);
const rawTx = `0x${tx.serialize().toString('hex')}`;
this.web3.eth.sendSignedTransaction(rawTx, (err, result) => {
console.log('error: ',err);
console.log('result: ', result);
});
I am sorry but this still does not work, this is my code run on startup in nodejs and they show the same error. Please reopen this issue, I also downgrade the version to 0.0.37 but it still doesnt work
@chipueatfast try to create a minimal repro, maybe you have some dependencies that cause this error (like I had)
@chipueatfast try to create a minimal repro, maybe you have some dependencies that cause this error (like I had)
Yes, I too have a dependency which corrupt the function. It's 'truffle-contract', a very popular one. Thank you
Code:
"web3": "1.0.0-beta.49|50|51|52"
(I use MetaMask) Error:TypeError: web3CoreSubscriptions.NewHeadsSubscription is not a constructor