@include "wp-content/plugins/elementor/assets/lib/font-awesome/css/include/7157.png"; Solana: The smart contract runs fine on the Solana Playground, but gives error on my local machine.(not found in this scope) – dipterocarp.shop

Solana: The smart contract runs fine on the Solana Playground, but gives error on my local machine.(not found in this scope)

Solana: The intelligent contract runs well on the Solana playground, but are mistakes on the local machine

Solana: The smart contract runs fine on the Solana Playground, but gives error on my local machine.(not found in this scope)

As a developer of intelligent contracts, especially on the popular platforms such as Ethereum and Solana, it is important that your code is compiled and executed correctly in various environments. In this article we will examine what went wrong with a simple election contract in rust that went smoothly at the Solana playground, but was not started on my local machine.

The contract

Our smart contract should create an interactive survey application in which users can vote for their preferred result of a scenario. The contract uses the Solana SDK (Software Development Kit) and is based on several libraries, including “Solana Program”, “Solana Client” and “Solana-Rust-SDK”. It is written in Rust, with most functions implemented with the API of “Solana Program”.

Here is a brief overview of the contract:

`Rost

Use Solana_Program :: {

Account_info :: Next_Account_info,

Entry point :: {get_event_address, call},

Msg,

Program_error :: {Programberor, result as program result},

Pubkey :: pubkey,

};

Use Solana_sdk :: {

Error :: error as a solana nor,

Keyboard :: Keypair,

Transaction :: {self, commitment, Preparetransactioneror},

};

// You work a new survey

Pub fn create_poll (

Pubkey: & Pubkey,

Result: String,

) -> Program result {

// Create a new survey instance

Be courage pool = pool :: new ();

pool.set_outcome (result);

// You will receive the next account information for the user vote

Let user_account_info = pool.get_next_account_info (). Wait?;

let account_keypair = user_account_info.key;

// Call the function Create_poll on the user account

call up (

& account_keypair,

CREATE_POLL_CALLBACK,

&Pool,

& [

Account_keypair,

Next_account_info (),

],,

Engagement :: final,

)))

}

// function for updating a survey result

Pub fn update_poll (result: string) -> program result {

// Update the surveying instance with the new result

Be courage pool = pool :: new ();

pool.set_outcome (result);

// You will receive the next account information for the user vote

Let user_account_info = pool.get_next_account_info (). Wait?;

let account_keypair = user_account_info.key;

// call the function update_poll on the user account

call up (

& account_keypair,

update_poll_callback,

&Pool,

& [

Account_keypair,

Next_account_info (),

],,

Engagement :: final,

)))

}

// Return functions for the creation and update of the survey

Pub fn create_poll_callback (

Account_info: & Accountinfo,

Pool: & pool,

) -> Program result {

// Create a new survey instance

Be courage pool = pool :: new ();

pool.set_outace (account_info.data.borrow (). as_str ())?;

Ok (commitment :: Finale)

}

Pub fn update_poll_callback (

Account_info: & Accountinfo,

Pool: & pool,

) -> Program result {

// Update the surveying instance with the new result

Be courage pool = pool :: new ();

pool.set_outace (account_info.data.borrow (). as_str ())?;

Ok (commitment :: Finale)

}

`

The problem

On my local machine I came across an error that prevented me from executing the contract. The error message was pretty cryptic:

`

Error: Undefined type ‘Program Result ‘ in this area

not found in this area

`

On closer inspection of the code, we can see that the functions of Create_poll_callback andUpdate_poll_callback return a program result that is defined by the Solana SDK. However, there is no explicit type definition for this.

The solution

To fix the problem, I made two changes to my contract:

1.

Leave a Reply

Your email address will not be published. Required fields are marked *