After some recent high profile hacks, learn how to navigate Web3 safer by running your transactions in Brownie. Recent hacks have been so brazen as to inject malicious scripts into the UI, meaning you cannot necessarily trust a protocol's website nowadays.
The basic principles to increase your safety are as follows.:
- Open a forked mainnet console using Brownie
- Inspect the transaction details in Metamask
- Decipher the transaction details using Brownie's
decode_input
- Run the transaction using Brownie.
- Test the output matches expectations.
- Exit the mainnet-fork
- Launch a console in mainnet
- Run the same transaction
Launch a fork of the mainnet to simulate transactions. Use this to preview the transaction you're about to run.
> brownie console --network mainnet-fork
Translate raw hex data from a Metamask contract preview. Built-in function for any Brownie Contract container.
> Contract(<address>).decode_input(<hex_data>)
On development networks brownie can unlock accounts without the private key. Accounts can be unlocked in the brownie config file or with the following command.
> accounts.at(<address>, force=True)
To run your transaction on mainnet, you must first provide Brownie your private key
> brownie accounts new <id>
To later load these accounts you'll provide a password set on import
> accounts.load(<id>)
Convert human readable units of ETH into raw wei (10 ** -18)
> Wei('1 ether')
> 1000000000000000000