1

Hello im trying to build simple smart contract using anchor and solang but when im trying "anchor build" command im getting this error:

info: Solang version v0.3.3
help: found contract 'helloworld'
   ┌─ C:\Users\Jason\Desktop\asd\helloworld\solidity\helloworld.sol:2:1
   │
 2 │ ╭ contract helloworld {
 3 │ │     bool private value = true;
 4 │ │
 5 │ │     @payer(payer)
   · │
20 │ │     }
21 │ │ }
   │ ╰─^

info: contract helloworld uses at least 17 bytes account data
info: Generating LLVM IR for contract helloworld with target Solana
info: Saving binary C:\Users\Jason\Desktop\asd\helloworld\target\deploy\helloworld.so for contract helloworld
info: Generating Anchor metadata for contract helloworld
info: Saving metadata C:\Users\Jason\Desktop\asd\helloworld\target/idl\helloworld.json for contract helloworld
Error: missing field `discriminator` at line 28 column 5

this is the contract im trying to build

contract helloworld {
    bool private value = true;

    @payer(payer)
    constructor() {
        print("Hello, World!");
    }

    /// A message that can be called on instantiated contracts.
    /// This one flips the value of the stored `bool` from `true`
    /// to `false` and vice versa.
    function flip() public {
            value = !value;
    }

    /// Simply returns the current value of our `bool`.
    function get() public view returns (bool) {
            return value;
    }
}
1
  • 1
    The error says "Error: missing field discriminator at line 28 column 5" but it looks like we're only seeing up to line 21. Is there more later down?
    – Jon C
    Commented Apr 26 at 12:51

2 Answers 2

0

If you are following the Solang getting started guide, use anchor version 0.28.0

Anchor "avm" installation instructions: https://book.anchor-lang.com/getting_started/installation.html

Install version 0.28.0

avm install 0.28.0

Use version 0.28.0

avm use 0.28.0
0
avm install 0.30.1
avm use 0.30.1

add this in Cargo.toml

[features]
idl-build = ["anchor-lang/idl-build"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.