Giter Club home page Giter Club logo

web3py-helper's Introduction

web3py-helper

Helper module for web3py beta 4

Documentation

The main python file shows some examples on how to use the helper, it is very similar to the following documentation

Account

This is how you can generate a local encrypted new account, save it locally and load it

account = Account(web3).new().save(accountfilepath, accountpassword)
account = Account(web3).load(accountfilepath, accountpassword)

Send money from the current local account to an address account.sendTo(to, wei, config.chainId)

Deploy a smart contract

How to deploy a smart contract on the block chain

scd = SmartContractDeployer(web3).loadSolidity(contractfilepath)
scd.compileSol()
scd.saveCompiledSol(compiledsolpath)
tr = scd.deploy(account.account.address,["MyArgs"],contractName="<stdin>:greeter", chainId=config.chainId)
tx = account.launchTransaction(tr)
scd.saveTx(tx, compiledfiletx)

Users have to manually validate every transaction is gonna sign for Approuve a transaction

Call methods on smart contract

You need to re-ling to your published smart contract with the compiled smart contract and a transaction hash

scc = SmartContractCaller(web3, compiledfiletx, compiledsolpath, "<stdin>:greeter")
address = account.account.address
n = web3.eth.getTransactionCount(address)

To read a function or value/state directly on the Ethereum node print('Contract value: {}'.format(scc.contractInstance.call().greet()))

To use a function that will cost gas

prepared_transaction = scc.contractInstance.buildTransaction().add(1)
updated_transaction = scc.updateTransaction(address, prepared_transaction, gas=50000, gasPrice=18000000000)
tx = account.launchTransaction(updated_transaction)

Color Printing

Some pretty printing functions (for block and transaction) can be used on filters, for example : Filter

Todo

  • Code
  • Basic documentation
  • Clean the code
  • Renaming methods
  • Refactoring
  • Add checks
  • Import ChainId from web3, not from config

Issues

This issue is not related to my code, but can occur if using a Clique consensus POA (tested on an Azure private Ethereum Consortium). In this case extraData contain more information than expected:

File "/usr/local/lib/python3.5/dist-packages/web3-4.0.0b5-py3.5.egg/web3/middleware/pythonic.py", line 94, in to_hexbytes
    result, len(result), num_bytes
ValueError: The value HexBytes('0x...') is 97 bytes, but should be 32

Just edit pythonic.py and modify the following code :

line  80:  def to_hexbytes(num_bytes, val, variable_length=False, override=True):
...
line  91:    else:
line  92:      if override:
line  93:        return result
line  94:      else:
line  95:        raise ValueError(
...
line 169:    'extraData': to_hexbytes(32, variable_length=True),

web3py-helper's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.