Solitary Heling first 128 days of cold self-python block chain 042 Ethernet Square erc20 token 12

Solitary Heling first 128 days of cold self-python block chain 042 Ethernet Square erc20 token 12

【main content】

Erc20 today continue to use the standards to copy the code according to another article Bowen network of intelligent tutorials to annotate a contract can be issued tokens. 37 minutes learning common.

(Also finishing taking notes took about 51 minutes)

Details see the end the process of learning the learning process screen video.

 

[Study notes]

One, found that in my whole computer to configure the local node without storage cases, simple contract calls initiated transactions is wrong:

Another simpler method call yesterday learned

As Bowen: https://blog.csdn.net/weixin_34214500/article/details/87496864

```

contract.transact({'from':sub_address, 'gas': 90000}).approve(gas_address,amount_of_token)

# Authorization gas_address can be transferred amount_of_token tokens from sub_address

contract.transact({'from':gas_address,

'gas': 90000}).transferFrom(sub_address,wallet_address,1)

# Authorized Transfer

```

Today, this method was attempted:

```

    # --- using a simple method of gas has initiated the transaction, there is no manual method signature private key, run-time error

    #r=contract.transact({'from':spenderadd, 'gas': 90000}).transferFrom(owneradd,toadd,tovalue)

    #print(r)

    '''

        Using the above method, given as follows:

        Traceback (most recent call last):

        File "ptvsd_launcher.py", line 43, in <module>       

        main(ptvsdArgs)

        File "__main__.py", line 434, in main

        run()

        File "__main__.py", line 312, in run_file

        runpy.run_path(target, run_name='__main__')  File "runpy.py", line 263, in run_path    pkg_name=pkg_name, script_name=fname)  File "runpy.py", line 96, in _run_module_code

        mod_name, mod_spec, pkg_name, script_name)

        File "runpy.py", line 85, in _run_code

        exec(code, run_globals)

        File "mint_contract.py", line 169, in <module>

        transerFrom(w2add,wallet_address,w3add,50)

        File "mint_contract.py", line 156, in traValueError: {'code': -32601, 'message': 'The method eth_sendTransaction does not exist/is not available'}

    '''

```

And finally we had to manually private key signature, and then broadcast deal for the job.

 

Third, today completed Py Code

```

import time

from web3 import Web3, HTTPProvider

 

import contract_abi

 

contract_address = "0xf89074dcdd8798b7e20b8cd88a9a38f27479411c" #CloudImage tokens contract address, is my own creation (deployment) smart contract

 

# The following two lines define the contract is to deploy a node (Node Creation) information private and public keys

wallet_private_key = "D8EF07D32389148E9DA6C54237BD5A39C92917D59340AA5D6064485C01E96FB2" # fox private purse

wallet_address = "0x5227C3EF48B5A1bcF784593e46D9579D26a3b592" # fox public purse, wallet address is, is a node on the network eth.

The following lines defined in the information node 2

w2pkey = "D5EC2E192E0362FF81B46F6AFB331772F85CE9B4A79F2A0962858301E72AAF1C" # private

w2add = "0xe2d6c2f289c53B5aEA44C47293Ba179a3bfa21f0" # public

 

The following lines defined in the information node 3

w3pkey = "1DCA9DF70412154D19FA78EFDAD1E9AC4AB60FB44DCFBC4323051DDF3141E98A" # private

w3add = "0xb40599fB0366DCf0ffe86677b005b3f20Dfa29aE" # public

 

The following lines defined in the information node 4

w4pkey="B2F1B869D373791B49A9058F4AF90E7AEEB883EAA783AC6244A6D6157B7C7BE6" #私钥

w4add = "0x70c8461366d5368B1E79CBFc2Acf4ba56C745977" # public

 

w3 = Web3 (HTTPProvider ( "https://ropsten.infura.io/v3/79124269dc454e47bee73f964c971d3c")) # string is inside the parameters of the application site on infura.io to a node address.

 

w3.eth.enable_unaudited_features () # make sure we know can happen problem.

 

contract = w3.eth.contract(address = contract_address, abi = contract_abi.abi)

# --- on the line, contract_abi.abi, is a reference to a list of variables stored in contract_abi.py file of abi

# --- the entire code is on eth web addresses and ABI connection list to get smart designated contract objects contract by intelligent contract

 

print (w3.eth.blockNumber) # print id last block of eth network

 

def transfer(toadd,v):

    nonce = w3.eth.getTransactionCount (wallet_address) # Here is a requirement, which node initiates the transaction, it returns the number of transactions initiated by the specified node address.

    '''

    Work carried out to prove nonce value (that is written in the header area of ​​Nonce value) calculated the nonce is not a miner during mining

    But: https: //blog.csdn.net/weixin_33941350/article/details/86836707

    A transaction requires the following parameters

    was rawTx = {

        Nuncio: '0x14'

        gasPrice "0x3B9ACA00"

        gasLimit: '0xC20A',

        to: '0x5fb30123b9efedcd15094266948fb7c862279ee1',

        value: '0x00',

        data: '0x' + '60fe47b1' + '000000000000000000000000000000000000000000000000000000000000000a'

    }

    nonce: a record number of transactions currently account sent, to prevent replay attacks, both from zero for each account nonce, to send each plus 1, will be processed after the current nonce nonce back surface of the processing is completed. Square series Ethernet (ETH & ETC) sending the transaction has three corresponding RPC interface, respectively eth_sendTransaction, eth_sendRawTransaction and personal_sendTransaction. (Or configured transmit content) of these three interfaces are required a transmission parameter nonce. Explained the official documentation of this parameter is: integer type, allows the same random number sent by covering their transactions in a pending state.

    You can query the current nonce account with RPC eth_getTransactionCount. At the same time this address and then initiate a transaction, if the nonce value eth_getTransactionCount obtained by the same on a nonce value, and then send the transaction with the same nonce value, if the fee is higher than the original transaction, then the first deal will be cover, lower than the original transaction fee if an exception occurs. Typically, gas price overwrite transaction sum in a pending state needs more than 110% of the original transaction.

    gasPrice: represents the gas price to wei units. If this is lower than the miners gasPrice desired gasPrice, the miners refused package deal.

    gasLimit: gas computing resource is a unit of measurement, each virtual machine EVM Square Ethernet operation have been assigned a number, to indicate which gas can be consumed. Therefore, the gas consumption of each transaction and the amount of computation and memory required for this exchange about. gasLimit set the gas cap of the transaction can be consumed, if the transaction actually consumed gas is less than or equal to gasLimit, a successful transaction and refund the excess gas. Otherwise, the transaction is not only obsolete, these have been consumed gas can not be returned, the miners still receive fees. The methodology for calculating the actual consumption of gas * gasPrice.

    '''

 

    # The following is a more complex method of some SendTransaction () method to transfer tokens, ----

    # ---- simple method refers to transact (), such as:

    '''

    contract.transact ({ 'from': sub_address, 'gas': 90000}). approve (gas_address, amount_of_token) # gas_address authorization token can be transferred from sub_address amount_of_token

    contract.transact({'from':gas_address, 'gas': 90000}).transferFrom(sub_address,wallet_address,1) #授权转移

    '''

    txn_dict = contract.functions.transfer(toadd,v).buildTransaction({

        'ChainId': 3, # refers to the test network

        'gas': 140000,

        'GasPrice': w3.toWei ('40 ',' Manuf '),

        'Nonce': nuncio,

    })

 

    signed_txn = w3.eth.account.signTransaction(txn_dict, private_key=wallet_private_key)

 

    result = w3.eth.sendRawTransaction(signed_txn.rawTransaction)

 

    tx_receipt = w3.eth.getTransactionReceipt(result)

 

    count = 0

    while tx_receipt is None and (count < 30):

 

        time.sleep(10)

 

        tx_receipt = w3.eth.getTransactionReceipt(result)

 

        print(tx_receipt)

 

        count+=1

 

    if tx_receipt is None:

        return {'status': 'failed', 'error': 'timeout'}

 

    processed_receipt = contract.events.Transfer().processReceipt(tx_receipt)

    # --- monitoring of events written contract with the wording of intelligent functions called smart contract is different. -----

    # --- The tx_receipt as a parameter, is to locate it? Which caused the event to determine the interaction?

 

    print(processed_receipt)

    # --- processed_receipt variables to get all the information broadcast events acquired by listening to events (contracts of this event broadcast two messages: one is the origination addresses of parties to the transaction, are two comments.)

   

    output = "Address {} broadcasted the opinion: {}"\

        .format(processed_receipt[0].args._from, processed_receipt[0].args._to)

    # Line of code on the two information are extracted using child objects to .args, args child object contains a name that identifies two events shaped the specified parameters of intelligent contracts.

    # - Note here the use of processed_receipt [0], contains a description of the contents of multiple events broadcast.

    print(output)

 

    return {'status': 'added', 'processed_receipt': processed_receipt}

 

def approve(sendadd,receiveadd,sendprivate,approvevalue):

    Address nonce = w3.eth.getTransactionCount (sendadd) # authorized to initiate operation node used here

 

    # The following function call initiated by the authorized contract

    txn_dict = contract.functions.approve(receiveadd,approvevalue).buildTransaction({

        'ChainId': 3, # refers to the test network

        'gas': 140000,

        'GasPrice': w3.toWei ('40 ',' Manuf '),

        'Nonce': nuncio,

    })

    # Started operating private key signature of the sender

    signed_txn = w3.eth.account.signTransaction (txn_dict, private_key = sendprivate) # here to initiate the authorization to use the private key to sign the operation node

    # Transaction information is sent to the network

    result = w3.eth.sendRawTransaction(signed_txn.rawTransaction)

    # Ready to receive send a receipt

    tx_receipt = w3.eth.getTransactionReceipt(result)

 

    count = 0

    while tx_receipt is None and (count < 60):

 

        time.sleep(10)

 

        tx_receipt = w3.eth.getTransactionReceipt(result)

 

        print(tx_receipt)

 

        count+=1

 

    # If you receive a receipt, inspection

    if tx_receipt is None:

        return {'status': 'failed', 'error': 'timeout'}

 

    # Monitor this transaction (Transaction) events broadcast

    processed_receipt = contract.events.Approval().processReceipt(tx_receipt)

    # --- monitoring of events written contract with the wording of intelligent functions called smart contract is different. -----

    # --- The tx_receipt as a parameter, is to locate it? Which caused the event to determine the interaction?

 

    print(processed_receipt)

    # --- processed_receipt variables to get all the information broadcast events acquired by listening to events (contracts of this event broadcast two messages: one is the origination addresses of parties to the transaction, are two comments.)

   

    output = "Address {} broadcasted the opinion: {}"\

        .format(processed_receipt[0].args._owner, processed_receipt[0].args._spender)

    # Line of code on the two information are extracted using child objects to .args, args child object contains a name that identifies two events shaped the specified parameters of intelligent contracts.

    # - Note here the use of processed_receipt [0], contains a description of the contents of multiple events broadcast.

    print(output)

 

    return {'status': 'added', 'processed_receipt': processed_receipt}

 

# Authorization query a node to another node can use token total current balance

def getAllowance(owneradd,spenderadd):

    return contract.functions.allowance(owneradd,spenderadd).call()

 

# Entrusted to use the Principal tokens fiduciary node call contracts transerFrom () method for transferring a specified number of tokens to third parties Principal

def transerFrom(spenderadd,spenderprikey,owneradd,toadd,tovalue):

    # --- using a simple method of gas has initiated the transaction, there is no manual method signature private key, run-time error

    #r=contract.transact({'from':spenderadd, 'gas': 90000}).transferFrom(owneradd,toadd,tovalue)

    #print(r)

    '''

        Using the above method, given as follows:

        Traceback (most recent call last):

        File "ptvsd_launcher.py", line 43, in <module>       

        main(ptvsdArgs)

        File "__main__.py", line 434, in main

        run()

        File "__main__.py", line 312, in run_file

        runpy.run_path(target, run_name='__main__')  File "runpy.py", line 263, in run_path    pkg_name=pkg_name, script_name=fname)  File "runpy.py", line 96, in _run_module_code

        mod_name, mod_spec, pkg_name, script_name)

        File "runpy.py", line 85, in _run_code

        exec(code, run_globals)

        File "mint_contract.py", line 169, in <module>

        transerFrom(w2add,wallet_address,w3add,50)

        File "mint_contract.py", line 156, in traValueError: {'code': -32601, 'message': 'The method eth_sendTransaction does not exist/is not available'}

    '''

    Using the previous method # ---

    # --- get nonce value

    Address nonce = w3.eth.getTransactionCount (spenderadd) # here used to initiate operation node of the transaction

 

    # The following function call initiated by a third-party contracts traded

    txn_dict = contract.functions.transferFrom(owneradd,toadd,tovalue).buildTransaction({

        'ChainId': 3, # refers to the test network

        'gas': 140000,

        'GasPrice': w3.toWei ('40 ',' Manuf '),

        'Nonce': nuncio,

    })

    # Started operating private key signature of the sender

    signed_txn = w3.eth.account.signTransaction (txn_dict, private_key = spenderprikey) # used here to initiate the transaction (that is, before receiving the authorization) operation node private key to sign

    # Transaction information is sent to the network

    result = w3.eth.sendRawTransaction(signed_txn.rawTransaction)

    # Ready to receive send a receipt

    tx_receipt = w3.eth.getTransactionReceipt(result)

 

    count = 0

    while tx_receipt is None and (count < 60):

 

        time.sleep(10)

 

        tx_receipt = w3.eth.getTransactionReceipt(result)

 

        print(tx_receipt)

 

        count+=1

 

    # If you receive a receipt, inspection

    if tx_receipt is None:

        return {'status': 'failed', 'error': 'timeout'}

 

    # Monitor this transaction (Transaction) events broadcast

    processed_receipt = contract.events.Transfer().processReceipt(tx_receipt)

    # --- monitoring of events written contract with the wording of intelligent functions called smart contract is different. -----

    # --- The tx_receipt as a parameter, is to locate it? Which caused the event to determine the interaction?

 

    print(processed_receipt)

    # --- processed_receipt variables to get all the information broadcast events acquired by listening to events (contracts of this event broadcast two messages: one is the origination addresses of parties to the transaction, are two comments.)

   

    output = "Address {} broadcasted the opinion: {}"\

        .format(processed_receipt[0].args._from, processed_receipt[0].args._to)

    # Line of code on the two information are extracted using child objects to .args, args child object contains a name that identifies two events shaped the specified parameters of intelligent contracts.

    # - Note here the use of processed_receipt [0], contains a description of the contents of multiple events broadcast.

    print(output)

 

    return {'status': 'added', 'processed_receipt': processed_receipt}



# Execution token transfer ---

#r=transfer(w2add,100)

#print(r)

 

# Node two nodes has been authorized to use a node 200 tokens

#r=approve(wallet_address,w2add,wallet_private_key,200)

#print(r)

 

# --- two nodes using the node transmits a token to the node three

#k=transerFrom(w2add,w2pkey,wallet_address,w3add,80)

#print(k)

 

# --- node two nodes use a token sent to the node four

k=transerFrom(w2add,w2pkey,wallet_address,w4add,50)

print(k)

 

# Query node to node authorize a two tokens available balance

r=getAllowance(wallet_address,w2add)

print ( 'authorization tokens can now Balance:', r)

```

Today, after the actual attempt, finally confirmed, after the authorization transaction execution, you can initiate a transaction on behalf of the transaction by the spender node accepts authorized to operate and issue a specified number of tokens owner node will be authorized to operate in this transaction (transaction authorization the amount of the predetermined number of tokens operation) sent to a third node.

So, this transaction transaction, the transaction is initiated spender node, the gas costs of this transaction will be paid by the spender node and manually initiate a private key private key signature executed when the node is used spender of transactions to be signed:

```

    nonce = w3.eth.getTransactionCount (spenderadd) # operation initiated this transaction node of address used here, is a spender node initiates the transaction matters.

 

```

Private key signature is also true:

```

    # Started operating private key signature of the sender

    signed_txn = w3.eth.account.signTransaction (txn_dict, private_key = spenderprikey) # used here to initiate the transaction (that is, before receiving the authorization spender) operation node private key to sign

    # Transaction information is sent to the network

    result = w3.eth.sendRawTransaction(signed_txn.rawTransaction)

    # Ready to receive send a receipt

    tx_receipt = w3.eth.getTransactionReceipt(result)

 

 

```

 

[Routine of self-description of the stick]

The last routine explanation, why should I insist on self-study.

 

"If I had not seen the sun, I can live with this dark, but the sun has made me desolate, desolate updated."

- Emily Dickinson

If you want to ask me how to look at his earlier life, I want answers yesterday and today will be completely different.

Yesterday, I live in desolate satisfaction, conscious peace of mind, took the bag body monthly salary, listening to the kind of command, almost invariably lived a life; sometimes mutual harmony to the people around children, sometimes tongue against preoccupied, show the trivial life, Chuiladanchang work; ecstasy, ecstasy, which can be integrated into the wonders of peace movement, the crushing of marching in step, marking time. At the time I think this is leisurely resignation of ordinary life, that is my fate up.

But one day, I saw a different sun and a different life circumstances under the sun - that's not desolate.

Today, I live in desolate pain, conscious desire to change, marching in step overwhelmed, watching the passage of life, who missed all eyes wide open remorse ... ...

Jiangzai I know I can not go back, I only change is the only right direction.

 

First, why old age is still learning

Give up a lot to go to dinner, go HI songs to play, go to the movies, catch drama ...... time, and then engaged in the learning age, should no longer seems to have been carried out, attracted endless people around puzzled and even contempt poor ......

But I do not want to give up the vow of lifelong learning.

because--

I do not agree with the status quo my life today!

Robert Kiyosaki told us, to reflect on their current life is not what you want, is not that the best motivation and answer?

Gone through most of their lives, and then only to find once, the moment the ongoing life is not what you want, it is a kind of experience?

Only the hearts of sincere feelings in order to answer this question, and then let the rich language is not portrayed.

Half of the trek experience, but found that does not go right, how many people have the courage to admit all the past is wrong?

And I'm willing to tell the past me: "! You're wrong."

So has experienced half a lifetime mistake, big pressure and age of the head, there is hope and a half from the end of the ladder frame and down again, then hobbled to climb another ladder in it?

I prefer to believe that there is hope!

This is why I want to continue to adhere to lifelong learning all the reasons to go on.

 

Second, at this age still learning these techniques do make sense

Pure technology this age are in fact no meaning.

But the interest can go beyond sense.

But technology can lead to changes in thinking, this is the meaning.

Invest in their own minds, their ideas of reform, this is the best preserved, more long-term investment, in the past I have never invested before, miss too much, then invest in their own minds from the start.

Robert Kiyosaki tells us that the really rich are rich time; real freedom is freedom to decide what they are willing to do.

Because I'm willing to do something where my interest, so I hope I have the freedom of choice that day, although that day may still be today from so far away, but I want to believe that more than a day to catch a few steps away from the hope that even taking a step forward.

Furthermore, although I might then have been unable to fully complete master these techniques, but the technology itself is the awakening of the heart may be enlightened, inspired, so as long as we understand that, I believe I will leave that to run away from me the more positive the faster the closer to the next point, and will not be abandoned by the unknown future that too far.

So how can I give up chasing the pace quest?

I want to believe: feeling too late, perhaps not too late.

 

I am grateful to have been concerned, I encourage you!

Q My number is: 578 652 607, look forward to hearing your advice.

 

 

[Simultaneous voice notes]

https://www.ximalaya.com/keji/19103006/273473338

 

[Learning] screen recording screen

Links: https://pan.baidu.com/s/1GK_TorQTh6V2NJy2cMFDOg

Extraction code: lpnh

 

Guess you like

Origin www.cnblogs.com/lhghroom/p/12569033.html