예제 #1
0
 def new_meeting_contract(self, meeting: Meeting):
     """
     Deploys a new meeting contract
     :param meeting: the meeting object associated with contract
     :return: Ethereum address of the contract
     """
     contract = self.w3.eth.contract(abi=self.contract_abi,
                                     bytecode=self.contract_bytecode)
     nonce = self.w3.eth.getTransactionCount(
         self.w3.toChecksumAddress('0x' + self.server_eth_address))
     log.debug('Nonce: ' + str(nonce))
     staff_dee_ids = [
         Web3.toChecksumAddress(staff_dee_id)
         for staff_dee_id in meeting.staff
     ]
     print(staff_dee_ids)
     contract_txn = contract.constructor(meeting.id,
                                         staff_dee_ids).buildTransaction({
                                             'nonce':
                                             nonce,
                                             'chainId':
                                             self.chain_id,
                                             'gas':
                                             2000000
                                         })
     signed = self.w3.eth.account.signTransaction(
         contract_txn, private_key=self.server_private_key)
     contract_txn_hash = self.w3.eth.sendRawTransaction(
         signed.rawTransaction)
     log.debug('Waiting for contract to be mined...')
     tx_receipt = self.w3.eth.waitForTransactionReceipt(contract_txn_hash)
     return str(tx_receipt.contractAddress)
예제 #2
0
def mint(contract):
    """
    mint zombie nft
    """
    transaction = pre_transaction(account.address)
    reward_address = Web3.toChecksumAddress("0xff827d59f973bc57eec55dce2955e03e6c81db30")
    token_uri = "https://raw.githubusercontent.com/weixuefeng/tokeuri/main/zombie.png"
    gas = contract.functions.awardItem(reward_address, token_uri).estimateGas(transaction)
    transaction['gas'] = gas
    tx = contract.functions.awardItem(reward_address, token_uri).buildTransaction(transaction)
    signed_txn = account.sign_transaction(tx)
    tx_hash = w3.toHex(w3.eth.sendRawTransaction(signed_txn.rawTransaction))
    print("mint txid: %s" % tx_hash)
예제 #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)
예제 #4
0
import sys
import json
import time
import csv

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

import config as cfg

#################################################################################
# GLOBALS
NONCE = 0
WALLET = Web3.toChecksumAddress(cfg.web3["wallet"])
PASSWD = cfg.web3["password"]
CC_ADD = Web3.toChecksumAddress(cfg.web3["contract-address"])
CC_ABI = ""

web3 = False
contract = False

#################################################################################
# FUNCTIONS

def getNonce():
    '''gets the NONCE to be used for the next transaction'''
    newnonce = web3.eth.getTransactionCount(WALLET)
    n = newnonce if newnonce > (NONCE+1) else NONCE+1
    print("nonce: {}".format(NONCE))
예제 #5
0
파일: agent.py 프로젝트: ricott1/submarine
            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 
    
    main_loop()