Self python isolated Heling cold block chain of 127 days Ether 041 11 Square token erc20

Self python isolated Heling cold block chain of 127 days Ether 041 11 Square token erc20

【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 54 minutes)

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

 

[Study notes]

First, there are two different methods of data transaction function calls smart contract contract in Python:

The method has been used before (a), by more complex sendTransaction () method to send gas to pay a transaction fee (transaction) broadcasts.

In this way, they divided into two types:

Bowen has the following description:

http://www.seerking.cn/article/32

https://www.xuesq.cn/thread-64380-1-1.html

Put it more clearly, quote reads as follows:

w3.eth.sendTransaction () only supports the sending unsigned affairs. To use it, your node must manage your private key. Since the node keys must be managed, so it can not be used with the host node.

w3.eth.sendRawtransaction()

Requirements have been signed and the transaction serialization. Therefore, it requires an additional sequence of steps to use, but allows you to broadcast transaction on the managed node. Of course, you may also need to use the local key.

They need to use sendRawtransaction ().

Relative to sendTransaction, sendRawtransaction a little more secure and free to the public switched node, sendTransaction apply to have their own server nodes running the whole situation

 

(B) learned today another more simple method call

The following blog post there are different methods, but found to be the same kind of usage, but different syntax statements:

https://learnku.com/articles/23193

```

tx_hash = cfToken.constructor().transact(transaction=tx_args0)

```

https://www.jianshu.com/p/0df051910509

```

# Executes the specified contain transaction (default auto consumption quantity of gas) method

contract.transact(transaction).myMethod(args,*kwargs)

# Execution method does not produce public trading

contract.call(transaction).myMethod(args,*kwargs)

Method # perform the specified gas and return gas consumption amount consumed value

contract.estimateGas(transaction).myMethod(*args, **kwargs)

```

As today to learn of the time, and therefore did not complete a real practice, the feeling here using this method is more convenient, because I want to solve the problem is -

Specifies the number of accepted authority node (spender) license node (owner) tokens (within authorized limits range) when sent to a third-party node, if you use the first method, the feeling of how to use the private key signature (with whom the private key signature?) these problems is very messy, it is still not fully sort out, but if you use this simple method, I found that does not appear to be a complicated process private key signature, but do not know whether by waiting practice test again tomorrow.

Today preliminary understanding, when you specify the number of accepted authority node (spender) license node (owner) tokens (within authorized limits range) and send it to third-party node, the node initiating the transaction is in fact accept the authority node (spender ), therefore, pay the cost of gas for this transaction (transaction) is authorized to accept node (spender), rather than the authority node (owner).

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

```

 

Two, nonce information when calling the intelligence contract Broadcasting (transaction) information

    Work carried out to prove nonce value (that is written in the header area of ​​Nonce value) calculated the nonce is not a miner in the transaction message when 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.

 

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 = "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._soapboxer, processed_receipt[0].args._opinion)

    # 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._soapboxer, processed_receipt[0].args._opinion)

    # 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,owneradd,toadd,tovalue):

    # --- get nonce value

 

# 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)

 

# Query node to node authorize a two tokens available balance

r=getAllowance(wallet_address,w2add)

print(r)

```

Here are some of the results:

```

# Here is the query authorization of the call:

Oh, the question arises. Please add the following details when reporting this Bug.

Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new

-----------------------------------------------------------------------

200 keys:

 6 . 2 4 2 2 1 \ p y t h o n F i l e s \ p t v s d _ l a u n c h e r . p y ' Space ' - - d e f a u l t ' Space ' - - c l i e n t ' Space ' - - h o s t ' Space ' l o c a l h o s t ' Space ' - - p o r t ' Space ' 1 9 8 8 ' Space ' i : \ M A K E A P P \ p y t h o n \ P y t h o n 3 6 5 \ 边 学 习 边 测

Test folder \ self PYTHON portion \ second stage \ 0127 Self Python _ _ block chain 041 credits own hair 1 1 \ mint _ contract. Py 'Space Enter

 

 

abnormal:

System.ArgumentOutOfRangeException: This value must be greater than or equal to zero, and the buffer size must be less than the console dimension.

Parameter name: top

The actual value is -3.

   在 System.Console.SetCursorPosition(Int32 left, Int32 top)

   在 Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)

   在 Microsoft.PowerShell.PSConsoleReadLine.ForceRender ()

   在 Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)

   在 Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)

   在 Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)     

   在 Microsoft.PowerShell.PSConsoleReadLine.InputLoop()

   在 Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)

-----------------------------------------------------------------------

PS I: \ MAKEAPP \ python \ Python365 \ test folder while studying \ self PYTHON section \ second stage \ 0127 block chain 041_ own self python_ send money 11> cd 'i: \ MAKEAPP \ python \ Python365 \ while studying

Edge test folder \ self PYTHON portion \ second stage \ 0127 041_ own self python_ block chains made Dollars 11 '; $ {env: PYTHONIOENCODING} =' UTF-8 '; $ {env: PYTHONUNBUFFERED} =' 1 '; &' g: \ w10_1 \ python \ python365 \ python.exe '' c: \ Users \ wp \ .vscode \ extensions \ ms-python.python-2019.6.24221 \ pythonFiles \ ptvsd_launcher.py '' --default '' --client '' --host '' localhost '' --port '' 1988 '' i: \ MAKEAPP \ python \ Python365 \ folder while learning test \ self PYTHON portion \ second stage \ 0127 self python _ 041_ own block chain made money 11 \ mint_contract.py '

Oh, the question arises. Please add the following details when reporting this Bug.

Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new

-----------------------------------------------------------------------

200 keys:

 6 . 2 4 2 2 1 \ p y t h o n F i l e s \ p t v s d _ l a u n c h e r . p y ' Space ' - - d e f a u l t ' Space ' - - c l i e n t ' Space ' - - h o s t ' Space ' l o c a l h o s t ' Space ' - - p o r t ' Space ' 1 9 8 8 ' Space ' i : \ M A K E A P P \ p y t h o n \ P y t h o n 3 6 5 \ 边 学 习 边 测

Test folder \ self PYTHON portion \ second stage \ 0127 Self Python _ _ block chain 041 credits own hair 1 1 \ mint _ contract. Py 'Space Enter

 

 

abnormal:

System.ArgumentOutOfRangeException: This value must be greater than or equal to zero, and the buffer size must be less than the console dimension.

Parameter name: top

The actual value is -3.

   在 System.Console.SetCursorPosition(Int32 left, Int32 top)

   在 Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)

   在 Microsoft.PowerShell.PSConsoleReadLine.ForceRender ()

   在 Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)

   在 Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)

   在 Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)     

   在 Microsoft.PowerShell.PSConsoleReadLine.InputLoop()

ct.py'

6043050

200

```

[Share] my self-perception

You and I have completely given up unless at the bottom of life, complete paralysis of their own, or I think everyone has wanted to achieve a transition class heart. The problem is that I am qualified and capable transition it?

We thought of having to change their present living conditions, I felt so hard, or how is this possible?

A further weigh their own will find, as if they have no money, no father can fight, and no backing available, or forget it!

In fact, the conditions of his own creation, and not all of the conditions are imagined so unattainable, such as -

Self-study this matter.

Welcome to the exchange, my qq number is: 578 652 607.

 

[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.

 

 

[Simultaneous voice notes]

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

 

[Learning] screen recording screen

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

Extraction code: xk33

 

Guess you like

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