Skip to main content

Wallets based on SALT instead of Nonce.

Project description

Bifrost

important: Work-In-Progress. No production software.

TOC

Install

Install from PyPI

# Virtualenv
(pyenv)$ pip install bifrost

# Main Python shell
$ sudo -H pip install bifrost 

Install from sources

# Ubuntu 18.04+
# Required packages
sudo apt install -y python3-dev git virtualenv

# Create and activate virtualenv
$ virtualenv -p python3 pyenv
(pyenv) $ source pyenv/bin/activate

# clone Repo
(pyenv) $ git clone https://gitlab.com/dtecdeal/lab/bifrost /path/to/destination/folder
(pyenv) $ cd /path/to/destination/folder/Python
(pyenv) $ python setup.py install

Usage

Create wallet

import os
from web3 import Web3
from bifrost import Bifrost

SIGNER_PK = os.environ.get('SIGNER_PK', "{default-signer-pk}")
FACTORY_ADDRESS = os.environ.get('FACTORY_ADDRESS', "{default-factory-address}")
RPC_URL = os.environ.get('RPC_URL', "{default-RPC-URL}")
BIFROST_FACTORY = os.environ.get('BIFROST_FACTORY', "{bifrost-factory}")


w3Provider = Web3.HTTPProvider(RPC_URL)
w3 = Web3(w3Provider)
signer_account = w3.eth.account.privateKeyToAccount(SIGNER_PK)

bifrost = Bifrost(BIFROST_FACTORY, signer_account, w3Provider)

address_salt = 1
address = bifrost.getAddress(address_salt)
address_is_deployed = bifrost.isDeployed(address_salt)

print('''
    Signer: %s
    Salt: %s
    Address: %s
    IsDeployed: %s 
''' % (signer_account.address, address_salt, address, address_is_deployed))

Transfer ETH

import os
from web3 import Web3
from bifrost import Bifrost

SIGNER_PK = os.environ.get('SIGNER_PK', "{default-signer-pk}")
FACTORY_ADDRESS = os.environ.get('FACTORY_ADDRESS', "{default-factory-address}")
RPC_URL = os.environ.get('RPC_URL', "{default-RPC-URL}")
BIFROST_FACTORY = os.environ.get('BIFROST_FACTORY', "{bifrost-factory}")

w3Provider = Web3.HTTPProvider(RPC_URL)
w3 = Web3(w3Provider)
signer_account = w3.eth.account.privateKeyToAccount(SIGNER_PK)

bifrost = Bifrost(BIFROST_FACTORY, signer_account, w3Provider)

address_salt = 1

amount = int(.1 * 10 ** 18)

# Transfer ETH
# address should have more than .1 (amount) ETH
tx = bifrost.makeCall(address_salt, signer_account.address, amount)
print('ETH transfer: ', tx.hex())
w3.eth.waitForTransactionReceipt(tx)

Transfer ERC20

import os
import json
from web3 import Web3
from bifrost import Bifrost

SIGNER_PK = os.environ.get('SIGNER_PK', "{default-signer-pk}")
FACTORY_ADDRESS = os.environ.get('FACTORY_ADDRESS', "{default-factory-address}")
RPC_URL = os.environ.get('RPC_URL', "{default-RPC-URL}")
BIFROST_FACTORY = os.environ.get('BIFROST_FACTORY', "{bifrost-factory}")
ERC20_ADDRESS = os.environ.get('ERC20_ADDRESS', '{default-ERC20-address}')


w3Provider = Web3.HTTPProvider(RPC_URL)
w3 = Web3(w3Provider)
signer_account = w3.eth.account.privateKeyToAccount(SIGNER_PK)

bifrost = Bifrost(BIFROST_FACTORY, signer_account, w3Provider)

address_salt = 1

amount = int(.1 * 10 ** 18)
# Transfer ERC20
# address should have more than .1 (amount) ERC20
ERC20_abi = json.load(open('path/to/abi/IERC20.json', 'r'))
ERC20 = w3.eth.contract(abi=ERC20_abi)
call = ERC20.encodeABI('transfer', args=(signer_account.address, amount))
tx = bifrost.makeCall(address_salt, ERC20_ADDRESS, 0, call)
print('ERC20 transfer: ', tx.hex())

Note

Following error

{'code': -32000, 'message': 'gas required exceeds allowance (7447619) or always failing transaction'}

Mostly related with always failing transaction

Made it with ❤ by DTecDeal

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bifrost_py-0.0.5.tar.gz (4.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page