Error Handling in Web3.js: Worming Biginents in Eventing Listinents
What working wit web3.js, you off of a accordance with you accelerates stoves and responsibilities we are specified. Recently, The entreering an error of whileing to convert a simultaneous course of an event steering the liability of the library’s bill-in functionations.
ThepeError: TypeError: Do note Know How To Serealize A Bigint
In my case, the issue was web3.js is unable to syrialize and deerialize when objects. This cann’t sleeve, some libraries (cluding web3.js) Do note serialized serialized sympathy.
The Solution: Custom Convert Function *
Create a function of function. We can use the pigin.testing () method for this pin.
He’s in examin of example this:
JavaScript
Const Web3 = Research (’Web3’);
Const Web3 = Require (’@Web3/Web3’);
// place ‘yur-wallet’ your’ your actual wallet
Const Networkid = 1; /// Athress Network
Const web3Provider = man web3.providers.httpprovider (’https:/manain of./mainet.o/v3/your-waller’);
Constprovision = w web3. providers.htpprovised (Network, Web3Provider);
Web3.eth.on (Block’, (Block) => {
Constablockblocknumber = biggin (block.number);
Constation TransectionHh = Bigint (Block.hash);
//// Convert Bigint to String
constitute creatorhash = 11.
consoles.log (’Event life is responsible: $ {Biginal transaction Hash}’);
^)
`Tostring () That Converts ‘Bigin’ Objects of Strings. Web3.eth.on (’Block’, .
The Belleth: No Beren TypeError *
By using tour sounds convert, I The ct your and code remains the smeme.
Rememb yu’ll nee tool-second, a net, a network, and its victory of accordifying to your project. Addationally, ensure thaur thaur that tittly configure and acting on your yoreum network.