Esempio n. 1
0
    def __init__(self, config):
        self.config = config

        # Get the ETH Key
        self.auth_key_path = config["auth"]["key_path"]

        # Get Smart contract params
        self.block_chain_provider_url = config["smart_contract"][
            "bc_provider_url"]
        self.compiled_contract_path = config["smart_contract"][
            "meeting_contract_path"]
        self.chain_id = config["smart_contract"]["chain_id"]
        self.max_gas = config["smart_contract"]["max_gas"]

        # Get the private key from the keyfile
        with open(self.auth_key_path) as keyfile:
            encrypted_key = keyfile.read()
            keyfilejson = json.loads(encrypted_key)
            self.server_private_key = w3.eth.account.decrypt(
                encrypted_key, "leet")  # TODO: Ask user for passphrase
            self.server_eth_address = keyfilejson['address']

        # Get the Meeting contract ABI from the ABI file
        with open(self.compiled_contract_path) as contract_file:
            contract_file_data = contract_file.read()
            contract_json = json.loads(contract_file_data)
            self.contract_abi = contract_json['abi']
            self.contract_bytecode = contract_json['bytecode']

        log.debug('ETH provider URL: ' + self.block_chain_provider_url)
        self.w3 = Web3(Web3.HTTPProvider(self.block_chain_provider_url))
Esempio n. 2
0
def main():
    from web3.auto import Web3
    from web3.middleware import geth_poa_middleware
    from eth_account.datastructures import SignedTransaction

    w3 = Web3(Web3.HTTPProvider("https://rpc1.newchain.newtonproject.org"))
    w3.middleware_onion.inject(geth_poa_middleware, layer=0)

    print(f'blockNumber: {w3.eth.blockNumber}')

    with open('a4d79e4efecd77ba0e1b6551388a7d7c0778824a.json') as keyfile:
        encrypted_key = keyfile.read()
        private_key = w3.eth.account.decrypt(encrypted_key, '123qwe')
        # tip: do not save the key or password anywhere, especially into a shared source file

        account = w3.eth.account.privateKeyToAccount(private_key)
        print(f'address: {account.address}')

        nonce = w3.eth.getTransactionCount(account.address)
        print(f'nonce: {nonce}')

        gas_price = w3.eth.gasPrice
        print(f"gasPrice: {gas_price}")

        chain_id = 1007

        transaction = {
            'to': '0x29e9356eC2082f447a7F747bF8D83c35E858fb86',
            'value': w3.toWei(1, "ether"),
            'gas': 21000,
            'gasPrice': gas_price,
            'nonce': nonce,
            'chainId': chain_id
        }
        signed: SignedTransaction = w3.eth.account.sign_transaction(
            transaction, private_key)
        print(signed)
        # When you run sendRawTransaction, you get back the hash of the transaction:
        w3.eth.sendRawTransaction(signed.rawTransaction)
        print(f"tx hash: {w3.toHex(signed.hash)}")

        while True:
            try:
                receipt = w3.eth.getTransactionReceipt(signed.hash)
                print("transaction is confirmed.")
                print(receipt)

                break
            except TransactionNotFound:
                print("waiting for transaction to be confirmed.")
                time.sleep(3)
Esempio n. 3
0
    def setup(self) -> None:
        """
        Set up the agent.

        :return: None
        """
        self._resources = Resources.from_resource_dir(self._directory, None)
        assert self._resources is not None, "No resources initialized. Error in setup."
        self._resources.setup()

        self.w3 = Web3(Web3.HTTPProvider(
            "https://nile.dev-ocean.com"))  #"http://localhost:7545"))

        with open(
                'keystore/UTC--2019-10-19T15-13-02.082157851Z--719b682d53f15899376709fb372c98aa5a116799'
        ) as keyfile:
            encrypted_key = keyfile.read()
            self.private_key = self.w3.eth.account.decrypt(
                encrypted_key, 'submarine')

        master_contract_address = '0x7d5158372BC13D1bA316b44B9002821BE46652F5'

        master_contract_address = Web3.toChecksumAddress(
            master_contract_address)
        self.account = self.w3.eth.account.privateKeyToAccount(
            self.private_key)
        self.w3.eth.defaultAccount = self.account.address
        self.eventBehaviour = self.resources.behaviour_registry.fetch_all()[0]
        self.resultTask = self.resources.task_registry.fetch_all()[0]
        #my_address = '0x719b682d53f15899376709fb372c98aa5a116799'

        with open("abi.json") as f:
            abi = json.load(f)

        self.contract = self.w3.eth.contract(address=master_contract_address,
                                             abi=abi)
        self.address = master_contract_address

        print("master contract", self.contract)
Esempio n. 4
0
    def __init__(self, config):
        """
        Auth class for all authentication/singing and crypto needs
        :param config: config.Config object
        """
        self.config = config
        self.auth_key_path = config["auth"]["key_path"]
        self.block_chain_provider_url = config["smart_contract"][
            "bc_provider_url"]

        self.dee_id_abi_path = config["auth"]["deeid_abi_path"]

        with open(self.auth_key_path) as keyfile:
            encrypted_key = keyfile.read()
            keyfilejson = json.loads(encrypted_key)
            self.server_private_key = w3.eth.account.decrypt(
                encrypted_key, "leet")  # TODO: Ask user for passphrase
            self.server_eth_address = keyfilejson['address']

        with open(self.dee_id_abi_path) as f:
            self.dee_id_abi = json.load(f)

        self.w3 = Web3(Web3.HTTPProvider(self.block_chain_provider_url))
Esempio n. 5
0
    elif n==3:
        return method(args[0],args[1],args[2]).call()
    elif n==4:
        return method(args[0],args[1],args[2],args[3]).call()
    elif n==5:
        return method(args[0],args[1],args[2],args[3],args[4]).call()
    else:
        return False


def main ():
    # print (contract.functions.name_of_the_function("param", param1).call())
    print (makeCall(contract.functions.name_of_function, "param", param1))


#################################################################################
# MAIN

if __name__ == "__main__" :
    # Load ABI from file
    with open(cfg.web3["abi-file"]) as f:
        CC_ABI = json.load(f)

    # Connect to RPC
    web3 = Web3(Web3.HTTPProvider(cfg.web3["provider"])) # web3 = Web3(IPCProvider(cfg.web3["ipcMiddleware"]))
    web3.middleware_onion.inject(geth_poa_middleware, layer=0)

    # Instantiate Contract
    contract = web3.eth.contract(address=CC_ADD, abi=CC_ABI)
    
    main()
Esempio n. 6
0
            #oceanDid = event_args["oceanDid"]
            response = create_ocean_request({"command" : command, "did" : oceanDid})
            result = process_response(response)
            signed_txn = create_result_tx()
            w3.eth.sendRawTransaction(signed_txn.rawTransaction)
            
            length = len(event_filter.get_all_entries())#maybe dont need this

        time.sleep(2)




if __name__ == '__main__':

    w3 = Web3(Web3.HTTPProvider("http://localhost:7545"))

    with open('../keystore/UTC--2019-10-19T15-13-02.082157851Z--719b682d53f15899376709fb372c98aa5a116799') as keyfile:
        encrypted_key = keyfile.read()
        private_key = w3.eth.account.decrypt(encrypted_key, 'submarine')

    contract_address = '0x4B04928c8beEF8848920a8BA63176B7aB5Fc87e2'
    contractAddress = Web3.toChecksumAddress(contract_address)
    account =  w3.eth.account.privateKeyToAccount(private_key)
    w3.eth.defaultAccount = account.address

    with open("abi.json") as f:
        abi = json.load(f)

    contract = w3.eth.contract(address=contractAddress, abi=abi)
    contract.address = contractAddress 
Esempio n. 7
0
from web3.auto import Web3
import time
from secrets import graph_token, p_key
import requests
import json
import subprocess
import random
import string

w3 = Web3(Web3.HTTPProvider("http://ethberlin02.skalenodes.com:10013"))

contract_address = '0x1f1e8f456f60b7a5435920b54da5525974ab6bfd'
contractAddress = Web3.toChecksumAddress(contract_address)
account =  w3.eth.account.from_key(p_key)
w3.eth.defaultAccount = account.address

with open("abi.json") as f:
    abi = json.load(f)

contract = w3.eth.contract(address=contractAddress, abi=abi)
contract.address = contractAddress  # THIS LINE!

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'
Esempio n. 8
0
__copyright__ = """ Copyright (c) 2021 Newton Foundation. All rights reserved."""
__author__ = '*****@*****.**'
__version__ = '1.0'

import datetime

from web3.auto import Web3
from web3.middleware import geth_poa_middleware

import newchain.config as config
import newchain.utils as utils
from newchain.contracts import constant

# 构造 web3
w3 = Web3(Web3.HTTPProvider(config.RPC))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)

# 获取账户信息
account = w3.eth.account.privateKeyToAccount(config.PRIVATE_KEY)
chain_id = int(w3.net.version)
gas_price = w3.eth.gasPrice

# 获取合约信息
zombie = utils.get_zombie_contract(w3)
zero_value_new = Web3.toWei("0", 'ether')


def mint(contract):
    """
    mint zombie nft