Here is the article:
Error that migrates from the anchor to Solana: unable to pass the accounting as a topic
Symbocching my journey from anchor migration 0.29.0 to Solana 1.9.2, I found a problem that made me persecuted. The error message indicated me a validation function that expects an object accounting 'or simply' unsckedcount 'as a topic. However, this unexpected behavior caught me by surprise.
The migration process provides for the update of various components and bookstores to align with the latest version of Solana. A crucial step is to change the API of anchor bookcase to meet the new Solana requirements. Unfortunately, I found a critical bug that prevented me from successfully migrating my code.
O bug: account migration error
In the 0.29.0 anchor, I used theaccount_info ‘function to extract the account values. When I moved to Solana 1.9.2, I tried to pass through a “delegable object” as a topic for a static method that uses these data. However, this approach was unable to produce the desired results.
Here is an extract of the example code that shows how I tried to solve this problem:
`Javascript
Import {anchor} of ‘@@ anchor-rocol/anchor-node’;
Import {accounting} of “solana-program”;
Contecount = New Anncho.unchechedacaccount (0, ‘Anchimint1 …’);
Const SolanaCacount = New Anncho.ACCODUTINFO (ANCHORACCOCOUNT);
// trying to overcome the account as a topic
Static Extractvalue (SolanaCacount) {
Return SolanaCacount.Value;
}
Console.log (extractovalue (SolanaCacount)); // Expected output: 1234567890ABCDEF
// error in an attempt to use the account_info function
Static Extractvalue (accounting) {
Const Value = accounting.Value;
Return value; // Expected output: 1234567890ABCDEF (must be 1.234567890ABCDEF)
}
Console.log (Extractvalue (accounting)); // Exit expected: Error: Typeeerror Uncathed: it is not possible to read Null’s “value” property
`
As you can see, the functionaccount_infogives a value 'null' when it has moved on to static methods that are expected to be an
non -controlled account or account. This is probably due to the updates and changes of the API anchor bookcase.
Alternative solutions and solutions
To solve this problem, I had to review my code base and regulate the use of the anchoring fipas. In particular, I discovered that I was using the function account_info
incorrectly. Instead of directly going through an “uncontroll, I should have used the” Get_acCount_info () “method, which returns a Solana-Program-Conta-Info.
Here is a revised code extract:
`Javascript
Import {anchor} of ‘@@ anchor-rocol/anchor-node’;
Import {accounting} of “solana-program”;
Contecount = New Anncho.unchechedacaccount (0, ‘Anchimint1 …’);
Const SolanaCacount = New Anncho.ACCODUTINFO (ANCHORACCOCOUNT);
// Using the Get_Cacount_info method to extract the values
Static Extractvalue (SolanaCacount) {
Return accounting.get (SolanaCacount). Values;
}
Console.log (extractovalue (SolanaCacount)); // Expected output: 1234567890ABCDEF
Console.log (Accounting.Get (SolanaCacount). Value); // Expected output: 1.234567890ABCDEF
`
In making these adjustments, I was able to successfully migrate my anchor code 0.29.0 to Solana 1.9.2 and resolve unexpected behavior by passing the objectsaccounting or misunderstanding as arguments for static methods.
Conclusion
As you can see, the anchoring migration 0.29.0 in Solana 1.9.2 has required some careful changes to explain the changes to the requirements of the API bookshop. However, with a little patience and persistence, it is possible to overcome these challenges and successfully migrate their code base.