near-sdk-rs | Rust library for writing NEAR smart contracts | Cryptocurrency library
kandi X-RAY | near-sdk-rs Summary
kandi X-RAY | near-sdk-rs Summary
Previously known as near-bindgen.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of near-sdk-rs
near-sdk-rs Key Features
near-sdk-rs Examples and Code Snippets
Community Discussions
Trending Discussions on near-sdk-rs
QUESTION
This is my data model:
...ANSWER
Answered 2022-Feb-13 at 15:25You need to make sure you are updating the RaffleDetails
instance that is in the map, not a copy/clone of it.
I'm not familiar with UnorderedMap
, but it seems to me the get()
method returns a copy of the value that is in the map, so you are only updating the copied value. I don't know if UnorderedMap
allows you to mutate a value in it directly (skimming through the docs, I don't see such a method). What you can do though is re-insert the modified RaffleDetails
into the raffles
map (so as to replace the old one with the modified one).
I'm talking about something like this (I haven't tested compiling it):
QUESTION
I want to call the mint function:
...ANSWER
Answered 2021-Aug-24 at 15:47Currently the answer is to copy the mint
function from the standard implementation and customize as you see fit.
The better interface will be coming in the future updates.
QUESTION
I am using near-contract-standards for NFT. In the example, it has nft_mint which takes token owner id and token id to mint the token.
...ANSWER
Answered 2021-Aug-03 at 16:46If I understand the question correctly you'd like to combine nft_mint
with some sort of payable action that will pay the original creator of some "NFT token type"?
You can check the NFT Market repo here: https://github.com/near-apps/nft-market
This repository uses a separate market account and contract to allow NFT Owners to put NFTs up for sale. A little more than what you are looking for I think.
There is also a variant that uses "lazy minting" to only mint the NFTs when a user buys them from the market contract: https://github.com/near-apps/gnr8/
Again, it's a little more than what I think you want because the payment and buying is happening in a separate contract and the NFT transfer and minting is happening in the NFT contract, which is called from the market contract.
If you're looking for something to add your own payable NFT method to, you could start with this: https://github.com/near-apps/nft-series/
Which allows you to define an NFT type and you could charge users to mint 1/N of that type by making the nft_mint_type method payable and NOT require the owner of the type to be the minter.
FYI these approaches are non-standard, but work.
Feel free to reach out directly on Discord if you need any help with the examples above.
QUESTION
I want to implement the _burn(address account, uint256 amount)
function provided by OpenZepplin's ERC20 library. The smart contract will call this function when some condition is true.
The Rust fungible token example has a on_tokens_burned()
function, but it looks like a logger.
ANSWER
Answered 2021-May-10 at 01:35Here is some implementation of burn:
QUESTION
I want to know the function caller's ID and check his balance. Issue is that env::signer_account_id()
returns data of type AccountId
/String
while function ft_balance_of()
needs an input of type ValidAccountId
. ft_balance_of()
is an NEP-141 fungible token function.
ANSWER
Answered 2021-May-04 at 14:32ValidAccountId
is a wrapper around a AccountId
, which validates the string to ensure that it is a valid format. This is usually done when deserializing the JSON sent when calling the contract method. However, here you have to be explicit:
QUESTION
I want to delete the current contract and burn its NEAR balance when a condition is triggered.
Here's the Solidity version:
...ANSWER
Answered 2021-May-01 at 16:37Currently there is no API to burn NEAR tokens directly. One workaround is to set the beneficiary account id to system
. system
is an account that can never be created and is used internally for refunds. When the beneficiary account does not exist, the tokens transferred through account deletion are automatically burnt.
QUESTION
I have questions about: fungible Token example and NEP-21 itself.
- It's a possible situation when
escrow allowances > 0
, butaccount balance = 0
. Is it legal flow and why? - It never checks
account_id
exists or not. Why? Is it secure? - Anyone can call:
inc_allowance/dec_allowance
?
And for let owner_id = env::predecessor_account_id();
will be created new account, new escrow allowance automatically (if not exist). Is that logic correct and why?
get_account
always created a new account. It looks redundant.
For example:
...ANSWER
Answered 2021-Feb-11 at 01:37It's a possible situation when escrow allowances > 0, but account balance = 0. Is it legal flow and why?
AFAIU allowance is just a sanity upper bound that prevents abuse. Two accounts can have two allowance for the same account that together sum up to a number larger than account balance.
It never checks account_id exists or not. Why? Is it secure?
In a sharded blockchain it is impossible to check for account existence without an asynchronous cross-contract call, since that other account might live on a different shard. Additionally, by the time we get a reply from that other shard this account can be created/deleted.
Anyone can call: inc_allowance/dec_allowance?
It can be only called by the owner, see: https://github.com/near/near-sdk-rs/blob/master/examples/fungible-token/src/lib.rs#L106
And for let owner_id = env::predecessor_account_id(); will be created new account, new escrow allowance automatically (if not exist). Is that logic correct and why?
Yes. I am not sure, why this would be contradictory.
get_account always created a new account. It looks redundant.
It might be redundant, but it also might be optimized out by the compiler in situations like this one: https://github.com/near/near-sdk-rs/blob/master/examples/fungible-token/src/lib.rs#L213
transfer_from is never check owner_id as the real owner of the account. Is there logic to protect transferring only by real owners?
It is implied in this check: https://github.com/near/near-sdk-rs/blob/master/examples/fungible-token/src/lib.rs#L174-L180 If it is not the case of an escrow, then env::predecessor_account_id()
should be equal to owner_id
. So the receipt/transaction must have been sent from the account of the owner.
Why fungible token doesn't have a name/title?
We are working on adding metadata to our contracts, see our Q1 OKRs here: https://airtable.com/shrw0AD36eIbfEW02
Do the NEAR Protocol have some standard or logic for Fungible Tokens exchange?
We have partners working on implementing something similar, but I don't think we have a standard.
QUESTION
TLDR: NEAR's FungibleToken example is the goto standard for how to write simulation tests, and it isn't compiling.
https://github.com/thor314/FungibleToken details my odyssey of trying to get the Fungible Token example to compile, so I can model my Simulation Tests off of it. The ReadMe contains what I've tried so far.
The original repo lives inside the near_sdk
repo.
https://github.com/near/near-sdk-rs/tree/master/examples/fungible-token
After @sirwillem's useful answer, this post is updated to reflect a residing error in the sim test:
...ANSWER
Answered 2020-Dec-18 at 15:28Thank you for trudging into uncharted territory! We are still working to publish core crates in nearcore that the simulator depends on. Once we have this, we can publish it. This will stabilize it and you won't get these types of errors.
For now to fix what you have edit your Cargo.toml to the newest tag for both:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install near-sdk-rs
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page