Hot answers tagged

6

As of v4.2.1, deploying a contract with a local key is a lot more straightforward. From the question's example code, here is a new approach: w3 = Web3(HTTPProvider("https://ropsten.infura.io/v3/YOUR_PROJECT_ID")) contract_ = w3.eth.contract( abi=contract_interface['abi'], bytecode=contract_interface['bin']) acct = w3.eth.account....


6

Benefits of web3.js JavaScript is the only language that runs inside web browsers and thus you do not have another option when building user facing interfaces web3.js community is larger due to JavaScript being de facto frontend langauge Benefits of web3.py Please note that you can also use web3.py on desktop apps, command line, server side programming ...


5

The best way to store the keys will depend on how you need to use them. For example, if you don't need to sign with them in real time, you may want to keep them on a separate system that isn't usually online. You can then give that system minimal functionality - just signing the transactions that you need signed - then send the signed transactions to your ...


5

Two Issues Retrieving the creator value print ('Creator',fContract.call().creator) Use fContract.call().creator() here. Creating the contract fContract = web3.eth.contract(abi,contractAddress) Use web3.eth.contract(contractAddress, abi=abi) here. Why? Any time you access data in a contract from outside the EVM, you access it using a function. This ...


5

v3 vs v4 Update: The question was written using web3.py v3, when v3 was the latest stable version. v4 is now stable, and preferred. Note that there are docs available for both versions: v3 (old) and v4 (current). eventFilter in v3 eventFilter is only available in v4. The simplest solution is now to upgrade, with pip install --upgrade web3. If you can't, ...


5

Infura doesn't support filters. Per https://api.infura.io/v1/jsonrpc/ropsten/methods (from the documentation, these are the supported methods: { "get": [ "web3_clientVersion", "net_version", "net_listening", "net_peerCount", "eth_protocolVersion", "eth_syncing", "eth_mining", "eth_hashrate", "eth_gasPrice", "...


5

MetaMask is a browser extension, so it's only available from code running in the browser. So to use it from web3.py, you'd first have to find a way to run Python code in the browser. This is perhaps technically possible but definitely not worth the trouble. If you're writing code in the browser, stick with JavaScript (and therefore web3.js).


4

Unfortunately, there is no "return value" for a transaction. There are two typical patterns to simulate a return value: Mutate the state via a transaction and then read the resulting state by calling a view function. (Note that this gives you the state at the time you call the view function, not necessarily the state right after the transaction, since other ...


4

'the-passphrase' is password to be supplied by you, which will be used to encrypt new account's private key. So when you will access this new account, system will ask for password which was used to encrypt account's private key.


4

Solution Insert a special middleware in web3.py to handle geth-style proof-of-authority, like this: py> from web3 import Web3, IPCProvider # connect to the default geth --dev IPC location py> w3 = Web3(IPCProvider('/tmp/geth.ipc')) py> from web3.middleware import geth_poa_middleware # inject the poa compatibility middleware to the innermost ...


4

This is a very common error. You need to upgrade your python version. Web3 requires at least 3.5.3+ I hope this resolved your problem :D


3

Etherscan refers to these as "Internal transactions" and the terminology seems to have caught on. Searching for that term may help you discover other approaches. Some solutions in descending order of personal preference: Ideally, the solidity method should be written such that it will either throw an exception (providing a failed status value) or succeed ...


3

Through follow-up, it became clear that the custom contract factory ConciseContract was used. That can be specified this way: my_contract_instance = w3.eth.contract(..., ContractFactoryClass=ConciseContract) ConciseContract looks up the first function call as a contract method. So this: my_contract_instance.transact(transact_params).setSomeAddress(w3.eth....


3

You should do it both client-side and inside the smart contract. Validating data inside the smart contract will prevent users from sending malicious data. Validating client-side will prevent the user from submitting data that will fail and help you give them real-time feedback when dealing with transactions (writing data) since, if it fails, the gas used ...


3

web3 sends transactions using unlocked wallets, which requires that you unlock your account using the keyfile and the password prior to sending a transaction. web3 is then able to access the the private key from the unlocked wallet and sign the transaction. If you want to avoid unlocking the wallet, you need to sign the transaction yourself and send a raw ...


3

0x3078616263646566 is the hex representation of the UTF-8 encoding of the string "0xabcdef". "0" is hex 30, "x" is hex 78, and so on. Try passing in b'\xab\xcd\xef' as the data, instead. You can generate this byte string from hex with: import codecs raw_bytes = codecs.decode('abcdef', 'hex') assert raw_bytes == b'\xab\xcd\xef' It's also worth checking out ...


3

A general approach could look like: Create a contract that has a variable, say uint public val Add a method on the contract that sets that variable, say setVal(uint) Generate the contract ABI Initialize Web3(...), with a connection to your client Create a contract object with the source code Deploy the contract with contract.deploy() Use the ABI and ...


3

[This might be] an error regarding HTTPProvider not connecting to the "https://ropsten.etherscan.io" That's correct, you cannot use the etherscan.io API as a JSON-RPC server. Instead, I'd recommend running an Ethereum node locally that is synced with Ropsten, similar to how (I presume) you ran the private testnet. One way to do that would be: parity --...


3

eth_sendTransaction is not on the list of Allowed Methods shown at http://www.myetherapi.com/ eth_sendTransaction assumes that the node has access to the private key of the account that you're sending from, but myetherapi does not. So you'll have to sign locally and use sendRawTransaction. The most convenient way to do that (in Python) is with the w3.eth....


3

Compiling, deploying and generating ABI and contract address were successful. How do you know deployment was successful? Can you add the code where you wait for the transaction to complete and then you retrieve the contract address? For what it's worth, a typical compiler would turn your public mapping into a function in the ABI that is exactly equivalent ...


3

Private keys/EAO accounts are valid on all Ethereum chains -- testnets and mainnet included. This means that the LocalAccount object you're creating will be able to recieve tokens and ether on your test network (as well as the Ethereum foundation network). Technically, you don't need anything connected to the internet to generate an account. You just need ...


3

You can use the web3.personal.newAccount(password) method: Generates a new account in the node’s keychain encrypted with the given passphrase. Returns the address of the created account. py>> web3.personal.newAccount('the-passphrase') ['0xd3cda913deb6f67967b99d67acdfa1712c293601'] Note that for security purposes, nodes do not expose the private ...


3

[Q] Could web3 retrieve state of a value from previous block numbers instead of returning the its latest state value? Yes, in web3.py v4.0+. When making a contract call, you can specify a block number (or hash). These examples are from the web3.py docs: # You can call your contract method at a block number: >>> token_contract.functions.myBalance()...


3

I'll assume you already have a private key available, using something like extracting a private key from a geth keyfile, and that you are using Web3.py v4.2.0. The general approach is to: construct your contract with any initialization arguments build the transaction for the contract constructor sign the transaction with your private key broadcast the ...


3

You can use the following method in web3py to get events: myfilter = mycontract.eventFilter('EventName', {'fromBlock': 0,'toBlock': 'latest'}); eventlist = myfilter.get_all_entries() eventlist will be a list of dictionaries containing the parameters of each event that had happened. Hope this helps.


3

This is described in web3py Documentation Once you have your provider set and web3 instantiates you can do: signed_txn = w3.eth.account.signTransaction(dict( nonce=w3.eth.getTransactionCount('yourAddress'), gasPrice = w3.eth.gasPrice, gas = 100000, to='recipientAddress', value=web3.toWei(12345,'ether') ), 'yourprivatekey') w3.eth....


3

Wait for the receipt and read the gasUsed value, like so: from web3.auto import w3 transaction_hash = '0x...' receipt = w3.eth.waitForTransactionReceipt(transaction_hash) print(receipt.gasUsed) Naturally, you may have to set up your Web3 instance with different connection parameters. The auto import is just shorthand for a quick and dirty setup. If I ...


3

Unfortunately, the personal module is not standardized across clients. parity supports a different API than geth. Some alternatives for creating an account: Use locally managed keys, OR Create the accounts on the parity node using the CLI Local keys >>> my_account = w3.eth.account.create('add something random here to improve key generation') >&...


3

If you want convert private key to public key and not address, then I would recommend using eth-keys library. It is in the dependencies of eth-account library, which is in the dependencies of web3py. Private key, used for account generation, consists of 64 hexadecimal characters (32 bytes total). So, if you have 32-bytes private key, then public key can be ...


3

Take a look here: Mastering Ethereum - Keys and Addresses. This chapter walks step by step through the process for deriving the public key. I think the main issue is that the online encoder is not expecting a hex input. Try using web3.js which seems to work perfectly: key = "...


Only top voted, non community-wiki answers of a minimum length are eligible