Can't compile standalone ft_example from most recent sdk

Viewed 210

I am trying to get this example

https://github.com/near/near-sdk-rs/tree/master/examples/fungible-token

to build locally as a standalone folder from the sdk, so I changed all 3 Cargo.toml's to use

near-sdk = { git = "https://github.com/near/near-sdk-rs.git" }
near-contract-standards = { git = "https://github.com/near/near-sdk-rs.git" }

and got this error

error[E0424]: expected value, found module `self`
  --> ft/src/lib.rs:63:1
   |
63 | near_contract_standards::impl_fungible_token_core!(Contract, token, on_tokens_burned);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | `self` value is a keyword only available in methods with a `self` parameter
   | this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `sender_id` in this scope
  --> ft/src/lib.rs:63:1
   |
63 | near_contract_standards::impl_fungible_token_core!(Contract, token, on_tokens_burned);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `burned_amount` in this scope
  --> ft/src/lib.rs:63:1
   |
63 | near_contract_standards::impl_fungible_token_core!(Contract, token, on_tokens_burned);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0424]: expected value, found module `self`
  --> ft/src/lib.rs:65:1
   |
65 | near_contract_standards::impl_fungible_token_ar!(Contract, token, on_account_closed);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | `self` value is a keyword only available in methods with a `self` parameter
   | this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `account_id` in this scope
  --> ft/src/lib.rs:65:1
   |
65 | near_contract_standards::impl_fungible_token_ar!(Contract, token, on_account_closed);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `balance` in this scope
  --> ft/src/lib.rs:65:1
   |
65 | near_contract_standards::impl_fungible_token_ar!(Contract, token, on_account_closed);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
  --> ft/src/lib.rs:48:57
   |
48 |         let mut this = Self { token: FungibleToken::new(b"a"), reference, reference_hash };
   |                                                         ^^^^
   |                                                         |
   |                                                         expected struct `Vec`, found `&[u8; 1]`
   |                                                         help: try using a conversion method: `b"a".to_vec()`
   |
   = note: expected struct `Vec<u8>`
           found reference `&'static [u8; 1]`

error[E0308]: mismatched types
  --> ft/src/lib.rs:77:24
   |
77 |             reference: self.reference.clone(),
   |                        ^^^^^^^^^^^^^^^^^^^^^^
   |                        |
   |                        expected enum `std::option::Option`, found struct `std::string::String`
   |                        help: try using a variant of the expected enum: `Some(self.reference.clone())`
   |
   = note: expected enum `std::option::Option<std::string::String>`
            found struct `std::string::String`

error[E0308]: mismatched types
  --> ft/src/lib.rs:78:29
   |
78 |             reference_hash: self.reference_hash.clone(),
   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                             |
   |                             expected enum `std::option::Option`, found struct `Base64VecU8`
   |                             help: try using a variant of the expected enum: `Some(self.reference_hash.clone())`
   |
   = note: expected enum `std::option::Option<Base64VecU8>`
            found struct `Base64VecU8`

error: aborting due to 9 previous errors

Some errors have detailed explanations: E0308, E0424, E0425.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `fungible-token`

when I tried using the following version of the crates

near-sdk = { version = "=3.0.0-pre.2" }
near-contract-standards = { version = "=0.1.0-pre.2"}

I got this error

error: no rules expected the token ,
  --> ft/src/lib.rs:63:67
   |
63 | near_contract_standards::impl_fungible_token_core!(Contract, token, on_tokens_burned);
   |                                                                   ^ no rules expected this token in macro call

error[E0432]: unresolved import near_contract_standards::fungible_token::metadata::FT_METADATA_SPEC
  --> ft/src/lib.rs:19:59
   |
19 |     FungibleTokenMetadata, FungibleTokenMetadataProvider, FT_METADATA_SPEC,
   |                                                           ^^^^^^^^^^^^^^^^ no FT_METADATA_SPEC in fungible_token::metadata

error[E0433]: failed to resolve: could not find impl_fungible_token_ar in near_contract_standards
  --> ft/src/lib.rs:65:26
   |
65 | near_contract_standards::impl_fungible_token_ar!(Contract, token, on_account_closed);
   |                          ^^^^^^^^^^^^^^^^^^^^^^ could not find impl_fungible_token_ar in near_contract_standards

warning: unused import: PromiseOrValue
  --> ft/src/lib.rs:24:76
   |
24 | use near_sdk::{env, log, near_bindgen, AccountId, Balance, PanicOnDefault, PromiseOrValue};
   |                                                                            ^^^^^^^^^^^^^^
   |
   = note: #[warn(unused_imports)] on by default

error[E0560]: struct FungibleTokenMetadata has no field named spec
  --> ft/src/lib.rs:71:13
   |
71 |             spec: FT_METADATA_SPEC.to_string(),
   |             ^^^^ FungibleTokenMetadata does not have this field
   |
   = note: available fields are: version, name, symbol, reference, decimals

error[E0560]: struct FungibleTokenMetadata has no field named icon
  --> ft/src/lib.rs:74:13
   |
74 |             icon: Some(
   |             ^^^^ FungibleTokenMetadata does not have this field
   |
   = note: available fields are: version, name, symbol, reference, decimals

error[E0560]: struct FungibleTokenMetadata has no field named reference_hash
  --> ft/src/lib.rs:78:13
   |
78 |             reference_hash: self.reference_hash.clone(),
   |             ^^^^^^^^^^^^^^ FungibleTokenMetadata does not have this field
   |
   = note: available fields are: version, name, symbol, reference, decimals

error: aborting due to 6 previous errors; 1 warning emitted

I also had to comment out # source ../flags.sh in the build.sh, and this is the error that I get when I ./build.sh

What could be the cause of this issue? Please advise on how to proceed, would be much appreciated as I am still figuring out this new lovely ecosystem :)

1 Answers

thanks for your interest and explaining your attempts. At the time you posted this, the fungible token example is hot off the press. The crates haven't been published as there's some dependency untangling to address. Just to make sure I understand your process, did you copy/paste the fungible-token directory elsewhere?

If you run the build.sh file in that directory, does it compile? It should. If you run rustc --version could we get that value? For me it's rustc 1.47.0 (18bf6b4f0 2020-10-07). Also, please ensure you've done this for the target:

rustup target add wasm32-unknown-unknown

Perhaps you could run through this intro to make sure the basics are working: https://docs.near.org/docs/develop/contracts/rust/intro

Also, feel free to reach out in https://near.chat where we do our best to answer questions that may take a little more back-and-forth. Glad you found that example so quickly! It's so fresh it's still on the window sill, steaming.

Related