Coder Social home page Coder Social logo

near-examples / ft Goto Github PK

View Code? Open in Web Editor NEW
119.0 119.0 99.0 1019 KB

Example implementations of money-like tokens, where one token is the same as any other, using the NEP-141 spec (similar to ERC-20)

Home Page: https://github.com/nearprotocol/NEPs/blob/master/specs/Standards/Tokens/FungibleToken.md

License: MIT License

Rust 76.05% Shell 0.51% Batchfile 0.50% JavaScript 0.73% TypeScript 22.22%
cli ready-to-use rust

ft's People

Contributors

amgando avatar anaisurlichs avatar benkurrek avatar bucanero avatar chadoh avatar dependabot-preview[bot] avatar dzarezenko avatar frol avatar gagdiez avatar idea404 avatar janedegtiareva avatar jonathansampson avatar mattlockyer avatar mikedotexe avatar pablolion avatar thisisjoshford avatar vgrichina avatar volovyks avatar zavodil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ft's Issues

reporting error in AssemblyScript build

via km1tz on Discord:

"Error is thrown in build time inside near-sdk-core package."

Error Message

ERROR TS2304: Cannot find name 'encode'.
       this.setBytes(key, encode<T>(value));
 in ~lib/near-sdk-core/storage.ts(158,26)

ERROR TS2304: Cannot find name 'decode'.
     return decode<T>(bytes);
 in ~lib/near-sdk-core/util.ts(46,12)

"While inspecting further, I can see that encode and decode functions are defined inside near-sdk-core\assembly\as_types.d.ts and cannot figure out where is the problem. I've tried updating near-sdk-core and typescript compiler to latest version to latest version but it did not make any difference."

Replicated Locally

yarn build:as
yarn run v1.22.5
$ ./contracts/assemblyscript/build.js

compiling contract [ nep21-basic/main.ts ] to [ out/nep21-basic-as.wasm ]
 asconfig.js is deprecated use `asb`to build files.  NOTE: output now in ./build/release/ 
asc /Users/jlwaugh/Desktop/FT/contracts/assemblyscript/nep21-basic/main.ts -O3z --debug --measure --runPasses inlining-optimizing,dce --optimizeLevel 3 --shrinkLevel 3 --target release --binaryFile build/release/main.wasm
ERROR TS2304: Cannot find name 'encode'.

       this.setBytes(key, encode<T>(value));
                          ~~~~~~
 in ~lib/near-sdk-core/storage.ts(158,26)

ERROR TS2304: Cannot find name 'decode'.

     return decode<T>(bytes);
            ~~~~~~
 in ~lib/near-sdk-core/util.ts(46,12)

/Users/jlwaugh/Desktop/FT/node_modules/near-sdk-bindgen/compiler.js:19
        throw new Error(err);
        ^

Error: Error: 2 compile error(s)
    at cb (/Users/jlwaugh/Desktop/FT/node_modules/near-sdk-bindgen/compiler.js:19:15)
    at Object.main (/Users/jlwaugh/Desktop/FT/node_modules/assemblyscript/cli/asc.js:717:12)
    at compileProject (/Users/jlwaugh/Desktop/FT/node_modules/asbuild/dist/cli.js:191:9)
    at main (/Users/jlwaugh/Desktop/FT/node_modules/asbuild/dist/cli.js:92:9)
    at module.exports.compile (/Users/jlwaugh/Desktop/FT/node_modules/near-sdk-bindgen/compiler.js:42:3)
    at compileContract (/Users/jlwaugh/Desktop/FT/contracts/assemblyscript/build.js:23:3)
    at Array.map (<anonymous>)
    at Object.<anonymous> (/Users/jlwaugh/Desktop/FT/contracts/assemblyscript/build.js:6:16)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

tests / simulation fail

followed the tutorial until the tests. tried to run them

environment: ubuntu 21.04
rust: latest from 4 days ago

  thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"', /home/andrei/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.54.0/src/lib.rs:1959:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

Flesh out Rust README

Currently the README in the project root has an empty section for Rust. While the tests are a decent step toward informing a user about usage, there are some aspects of the fungible token that are particularly difficult to grasp without being spelled out. For instance, after initializing the contract and sending X fungible tokens to an account, we receive this error:

Error: GuestPanic [Error]: Smart contract panicked: panicked at 'The required attached deposit is 36500000000000000000000, but the given attached deposit is is 0', src/lib.rs:254:13

This is because we need to make sure that state storage doesn't get exploited. Folks have to pay for the storage it will take, essentially. This ticket is for the DevX team to take a first stab at explaining how to use a fungible token, and then tag and pull in @evgenykuzyakov for review.

I believe there are two approaches to fleshing this out:

  1. Give instructions on how to use near-shell to build, deploy, initialize, and use the fungible token, demonstrating escrow and expected behavior.
  2. Use near-api-js and a simple web interface (like we have with Token Contract AS) where folks can add commands in the developer console of their browser and see the results.

Acceptance Criteria:

  • What is generally written above
  • Use the unit tests in the contracts in order to determine ways in which we can give example scenarios using near shell. For instance, walk the use through how to create and initialize a fungible token, send directly from Alice to Bob. Then have Charlie be an escrow between the two, incrementing allowance, etc. A user should be able to come to the README and run a few near shell commands and try out sending fungible tokens around.

Error encountered when creating Token - formatting a string: Input string was not in a correct format

near call $ID new '{"owner_id": "'$ID'", "total_supply": "1000000000000000", "metadata": { "spec": "https://upload.wikimedia.org/wikipedia/commons/thumb/archive/7/76/20110911121639!Lazio_Coat_of_Arms.svg/120px-Lazio_Coat_of_Arms.svg.png", "name": "Vibe Project Tokens", "symbol": "VIBE", "decimals": 8 }}' --accountId $ID

Error formatting a string: Input string was not in a correct format..
At line:1 char:1

  • near call $ID new '{"owner_id": "'$ID'", "total_supply": "10000000000 ...
  •   + CategoryInfo          : InvalidOperation: ({0}", "total_su...decimals": 8 }}:String) [], RuntimeException
      + FullyQualifiedErrorId : FormatError
    
    

cleanup punchlist

beforeEach hook always returns failures when testing FT with ava,can anyone help?

When I use main.ava.js to test FT whit ava, the beforeEach hook always throws failures. Below is the relevant logging, hope someone can help me.

` ✖ beforeEach hook for Can close empty balance account Rejected promise returned by test
✖ beforeEach hook for Simple transfer Rejected promise returned by test
✖ beforeEach hook for Total supply Rejected promise returned by test
✖ beforeEach hook for Can force close non-empty balance account Rejected promise returned by test
✖ 4 tests remaining in tests/main.ava.ts

beforeEach hook for Can close empty balance account

Rejected promise returned by test. Reason:

Error (TransactionError) {
message: '{"result":{"receipts_outcome":[{"block_hash":"sqRkmRMXyr9ZntukqEwSbdoqkF83vvctKnHHCcET6NX","id":"EXi5BYRuLAtvgFutnHBFnp3sdWcX5qhSb1UmgyA8WJnz","outcome":{"executor_id":"fungible-token.test.near","gas_burnt":2478387861555,"logs":[],"metadata":{"gas_profile":[{"cost":"CONTRACT_COMPILE_BASE","cost_category":"WASM_HOST_COST","gas_used":"35445963"},{"cost":"CONTRACT_COMPILE_BYTES","cost_category":"WASM_HOST_COST","gas_used":"50290551750"}],"version":1},"receipt_ids":["B7aDDWkf8zF3gAiniFsTFtqArCz9G9XsUfDPvcX7zVCJ"],"status":{"Failure":{"ActionError":{"index":0,"kind":{"FunctionCallError":{"ExecutionError":"Link Error: Error while importing \"env\".\"promise_batch_action_function_call_weight\": unknown import. Expected Function(FunctionType { params: [I64, I64, I64, I64, I64, I64, I64, I64], results: [] })"}}}}},"tokens_burnt":"2478387861555000000000"},"proof":[{"direction":"Left","hash":"ESvfpBxCQGqxmUvfBKwHbAcdKpS349WBky8Hv7fP8i6z"}]},{"block_hash":"BqLFCroAX53xJguskiH9tbPLfqbbzh1Hxsx6MrgvTEzL","id":"B7aDDWkf8zF3gAiniFsTFtqArCz9G9XsUfDPvcX7zVCJ","outcome":{"executor_id":"fungible-token.test.near","gas_burnt":223182562500,"logs":[],"metadata":{"gas_profile":[],"version":1},"receipt_ids":[],"status":{"SuccessValue":""},"tokens_burnt":"0"},"proof":[]}],"status":{"Failure":{"ActionError":{"index":0,"kind":{"FunctionCallError":{"ExecutionError":"Link Error: Error while importing \"env\".\"promise_batch_action_function_call_weight\": unknown import. Expected Function(FunctionType { params: [I64, I64, I64, I64, I64, I64, I64, I64], results: [] })"}}}}},"transaction":{"actions":[{"FunctionCall":{"args":"eyJvd25lcl9pZCI6InRlc3QubmVhciIsInRvdGFsX3N1cHBseSI6IjEwMDAwIn0=","deposit":"0","gas":30000000000000,"method_name":"new_default_meta"}}],"hash":"4oWzC5qB4dsTznq1NFAaHHwRD6fPhVdPoHyKaKBFvVta","nonce":3000001,"public_key":"ed25519:448iYi2H8MehSfcG652X6quoxwdrHAcgtheyutKtVMng","receiver_id":"fungible-token.test.near","signature":"ed25519:iTv4KNxXRSfUajLXP2TNGPGuBSKmSP3bkYeWiET3Zm2cHKLzQC3bVhKREYRnmTs96UADgk6NnFNibw4w1ofiCzF","signer_id":"fungible-token.test.near"},"transaction_outcome":{"block_hash":"sqRkmRMXyr9ZntukqEwSbdoqkF83vvctKnHHCcET6NX","id":"4oWzC5qB4dsTznq1NFAaHHwRD6fPhVdPoHyKaKBFvVta","outcome":{"executor_id":"fungible-token.test.near","gas_burnt":2428061863842,"logs":[],"metadata":{"gas_profile":null,"version":1},"receipt_ids":["EXi5BYRuLAtvgFutnHBFnp3sdWcX5qhSb1UmgyA8WJnz"],"status":{"SuccessReceiptId":"EXi5BYRuLAtvgFutnHBFnp3sdWcX5qhSb1UmgyA8WJnz"},"tokens_burnt":"2428061863842000000000"},"proof":[{"direction":"Right","hash":"76FRpWKRPCoUUxzDV7kBjqtLTNK5iyHoaCMQmy8ZafQ3"}]}},"startMs":1658990180091,"endMs":1658990182129,"config":{"network":"sandbox","rootAccountId":"test.near","rpcAddr":"http://localhost:6360","initialBalance":"100000000000000000000000000","homeDir":"/tmp/sandbox/9dfdc3b0-cc36-48e9-9b1d-d7857eb318bd","port":6360,"rm":false,"refDir":null}}',
}
`


My package.json in workspace:

{ "devDependencies": { "@types/bn.js": "^5.1.0", "ava": "^4.2.0", "ts-node": "^10.8.0", "bn": "^1.0.5", "bn.js": "^5.2.1", "near-workspaces": "^2.0.0" }, "dependencies": { } }

When call storage_balance_of() method, Unhandled Rejection (Error): [-32700] occured.

I'm developing Dapp on NEAR protocol.

And I want to cross call method.

I'm writing FT contract's storage_balance_of() method before call ross call method.
But Unhandled Rejection (Error): [-32700] occured.

What are the possible causes and countermeasures?

Unhandled Rejection (Error): [-32700] Parse error: Failed parsing args: missing field `account_id`

スクリーンショット 2022-11-06 14 34 07

frontend source code is here.

/**
 * get storage balance of account id function
 */
export async function storage_balance_of(account_id) {  
  let balance = await window.ftContract.storage_balance_of({
    account_id: account_id,
  });
  return balance;
}

example of querying balance in command line

Can we have in the readme an example for querying the balance of an account please?

Also the explorer doesn't support auto-detecting user's FT Tokens (like etherscan) right?

no cargo.toml file

hi, I tried to run script 'build' or cargo build - returns error
"error: could not find Cargo.toml in ...\FT or any parent directory"

for me it helped to add cargo.toml to main dir.

[profile.release]
codegen-units = 1
opt-level = "z"
lto = true
debug = false
panic = "abort"
overflow-checks = true

[workspace]
members = [
"ft",
"test-contract-defi",
]
exclude = [
"integration-tests"
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.