For the task
We hereby have the following contract
public static object Main(string method, Object [] args) {if (runtime.trigger == triggerType.verification) {if (method == “0214”) return true; } return false; }
His AVM is as follows, he is a certified contract and does not need to issue him.
55c56b6c766b00527ac46c766b51527ac4616168164e656f2e52756e74696d652e47657454726967676572009c6c766b52527ac46c766b52c3642a00 616c766b00c30430323134876c766b53527ac46c766b53c3640e00516c766b54527ac4620f0061006c766b54527ac46203006c766b54c3616c7566
X86cf7371f5511257f682cc47be48563a3ff03f51 ScriptHash: 0
Address: APBUyZNkemciUQurabSQBnnma7kGGhUPPL
Several gas transfers have been made to this address on TestNet.
The mission was left unattended for 24 hours in an area where many cattle were concentrated. It is true to call the task impossible.
profession
This article is an advice to you to bypass authentication contract development, first learn application contract development.
The learning curve for neo.org documents is no longer steep, but precipitous.
I sampled it and found no one who had successfully completed the study of the authentication contract following this document.
Therefore, I am full of confidence in my learning ability to climb this steep mountain, and I plan to teach you how to learn accreditation when I come back.
I’m back. I jumped off a cliff, too.
These are the money I withdrew from my bounty account.
So I succeeded? It was partially successful. On the way to try to withdraw these two sums of money using NEOGUI, I totally got cold.
I’m using the NEL ThinSDK-CS example from the wallet (github.com/NewEconoLab…)
After completing this task, I came to the following conclusion:
It is recommended that you bypass the development of authentication contract and learn the development of application contract first.
The difficulty lies in the fact that there are many concepts to understand and neoGUI does not cooperate well. If you see this, still undaunted, insist on climbing this mountain, we will talk later.
Password Contract:
The reward contract is a cipher contract
public static object Main(string method, Object [] args) {if (runtime.trigger == triggerType.verification) {if (method == “0214”) return true; } return false; }
It only returns true if the first argument is 0214 and runtime.trigger ==Verification.
For an authentication contract, return true to make the transaction work.
It’s easy to think of, where do you pass in this 0214? Which brings us to the whole deal and the authentication contract.
Authentication contracts and transactions
The authentication contract is executed during the transaction verification phase. If the authentication contract does not return true, then the transaction fails to be verified directly and cannot be written to the block, making it impossible to query the transaction.
An authentication contract is fundamentally different from an application contract in that the application contract must be executed in the block where the validation was successfully written.
NEO transactions have inputs and outputs. This is the business of the UTXO model, where the input to the transaction is a list, where each entry is a reference to a UTXO. The output of the transaction is the manufacture of a new UTXO.
The input and output of the transaction is money. Destroy the input and make the output. If you are confused about UTXO, you can go back and figure out UTXO.
The transaction includes the following:
- Input list
- Output list
- If it’s an application contract transaction, there’s an application contract script, and there’s something else
These together constitute an unsigned contract.
Did you find out there was no contract? What about the authentication contract?
Did you remember to sign it? You must know that when you transfer money to someone, you sign the transaction with your private key.
This is, in fact, a special case of the authentication contract.
1. Depending on how many input addresses a transaction has (i.e., the person paying the money), there must be several corresponding witnesses.
2. To sign a transaction is to add witnesses corresponding to the initiator of the transfer
3.NEO is a complete smart contract system. Each witness consists of two scripts, one is called verification script and the other is called execution script.
The above three points are not a little dizzy, don’t worry, there are more dizzy
The signature,
1. Each account address of NEO is a script, which is a two-instruction smart contract with pseudo-code as follows:
Push publickey
Syscall Checkwitness
The hash value of this script is the user’s address, which is usually expressed as a base58 string with the hash value salted and authenticated. The string value is equivalent to the hash value.
Therefore, the address of NEO is the hash value of the smart contract. The converse is also true. NEO’s hash value for each smart contract is an address.
So, I can send money to a smart contract, and I can withdraw money from a smart contract, because my address is actually a smart contract address.
2. The verification script of the witness is the smart contract corresponding to the address and cannot be modified. Different hashes cannot pass the verification.
3. The execution script of the witness is a smart contract used to provide parameters like the verification script.
So let’s look at what happens when you send money from my address to someone else.
1. To transfer money to others, you must enter the UTXO from your own address inside
2. Structure a trade
3. Add witnesses. The verification script is my script
4. Set up the witness execution script, which is a one-instruction smart contract, pseudo-code is:
Push signdata
5. Send rawData containing transaction data and witness data
6. Verify transaction, execute script push signdata, end, verify script push its own pubkey, then checksig, this function two parameters, just signdata and pubkey, check, if successful, the transaction is established. Otherwise, the deal is broken.
It’s more complicated than you think.
Take hanging red
Once we understand the relationship between the witnesses and the transaction, we can successfully take the money from the reward contract
Then set up a transfer transaction
Enter n, find utXO from the bounty contract address
Output 1, give yourself the address
Output 2 Optional: You can give change to the reward address
Witness: Checksum script = bounty contract
Execute script = parameter
Because the arguments are a string and an array
Flashback push
Pseudo code for
Push0 // Add 0
Pack // Creates an array with the 0 above, indicating an empty array
Push the bytes (” 0214 “. As the bytes ()) / / Push “0214”
Binary: 00C10430323134
I’ve given you the information, so I’ll just spell out a custom contract.
Don’t NEOGUI have tools, F12 call up, yes, go to test, guaranteed fun. You can understand the cliff learning curve.
And even if you do everything right, you can’t take it away.
I wondered here for a long time, and then I followed NEO bottom line line by line
There is a limitation that only push instructions can be allowed in the execution script, otherwise the direct script execution fails, the authentication contract fails, and the transaction is not established.
The pseudocode of the script we just executed is
Push0 // Add 0
Pack // Creates an array with the 0 above, indicating an empty array
Push the bytes (” 0214 “. As the bytes ()) / / Push “0214”
Binary: 00C10430323134
There is a pack, out of the allowed range, the transaction must fail.
So we know that there is no way to reference an array parameter in an authentication contract.
Fortunately, the second parameter of the reward contract is not actually used, just push anything
Let’s change the execution script to
Push0 // Add 0
Push the bytes (” 0214 “. As the bytes ()) / / Push “0214”
The binary value is 000430323134
Well, if you’re patient, go play NEOGUI and F12.
No release?
If you look at some of the NEO smart contract materials, you may notice that the contract was not released.
You don’t have to publish a smart contract, you don’t have to publish a smart contract, you can just call it, no problem.
So what happens is that in order for this smart contract to be called by appCall, it has to be published to the chain and pay a very high fee. Application contracts are basically like this, and they have internal storage for the sake of repeated calls.
So with all of that, it’s a lot easier to get started with an application contract than it is with an authentication contract.
The authentication contract need not be published.
What about the other client
This is NEL (a NEO China developer community organization)
An example of an SDK for developing a light wallet
C # version
Github.com/NewEconoLab…
The typescript version
Github.com/NewEconoLab…
Let’s demonstrate how to learn authentication contracts more smoothly with this example wallet
NEL public account has published this wallet transfer method
www.cnblogs.com/crazylights…
Start c# example
To get a light wallet test, click the thinWallet Test below
Because we take hanging red, actually do not need loadkey, just open the wallet, we do not need anyone’s signature to take out the money
Obtain utXO from bounty contract address
You can add a UTXO with smart contracts by right clicking on the Input field
Copy the suspended red contract in, or click loadAVm to read from avM
You can see the address of the contract displayed below
Then click refresh UTXO to get the UTXO of the xuan Hong contract, select one
Let’s take the 91.8 one
And then you see that the input is there
Output more than one (changeback) means change, we are good youth, do not take all
Witness also automatically adds a smart contract abbreviation (SC)
Add an output, pass it to yourself
Right-click in the output area and add an output
Fill in to whom, in what currency (gas), how much
The output then automatically adjusts the change
Try signing out, cannot send out, tell you that the execution script of the witness has not been configured
Configuration witness
Select the witness and right-click in the witness area
Yellow is the checksum script, he is the reward contract itself, can not be modified
Red is the configuration for executing the script, and we use a JSON instead of the unintuitive configuration
String adds some rules
The beginning of (STR) indicates that this is a string
The (int) beginning indicates that this is a BigINTEGER
There are (bin) (int160) (int256)
It’s easy to understand.
Click on Gencode to generate the execution script, but we know that the execution script with Array is not allowed, so change it.
Ok, ok
Come back and sign and broadcast
Done c.
Get a transaction ID dialog box
A successful deal
Everywhere you look, you can see that the money in the red has been withdrawn.
Write in the last
There is also a lot of money left in the hanging red, for those who want to explore, please do not take it all at once.
Author: Li Jianying
From the original: www.cnblogs.com/crazylights…