near / cargo-near

Cargo extension for building Rust smart contracts on NEAR
Apache License 2.0
33 stars 16 forks source link

[Question] Is it possible to compile "cargo-near" into "wasm"? #135

Closed KimCookieYa closed 5 months ago

KimCookieYa commented 6 months ago

I want to compile "cargo-near" into wasm and do "cargo near create-dev-account" inside react. But after git clone, I tried to compile it into wasm-pack, but I keep getting errors.

  1. Is it okay to compile "cargo-near" into wasm and use it?
  2. I want to create an account by calling create-dev-account inside the react rather than cli, what should I do?
frol commented 5 months ago

@KimCookieYa You don't need cargo-near for that. There is a faucet service that you just need to call with the account ID and public key, which will create a new account on testnet for you. There is also implementation for that in near-api-js:

https://github.com/near/near-api-js/blob/5518fe63fd492040f1f27293306c9e4db3f198a4/packages/wallet-account/src/near.ts#L113

Here is how it is used in near-cli (JS):

https://github.com/near/near-cli/blob/15cb2fc14280c18ee96c1f2c6e1be06027d2c2f2/commands/account/create.js#L128-L130

Just for the reference, here is the implementation inside near-cli-rs (which is used by cargo-near), that uses the faucet API to create a funded account on testnet: https://github.com/near/near-cli-rs/blob/main/src/commands/account/create_account/sponsor_by_faucet_service/mod.rs#L78-L83

Here are two testnet faucet services that I know: