README.md
contract
    Cargo.toml
    README.md
    build.sh
    compile.js
    src
        ad_spot.rs
        creative.rs
        lib.rs
        presentation.rs
nft-contract
    Cargo.toml
    README.md
    build.sh
    compile.js
    src
        approval.rs
        enumeration.rs
        events.rs
        internal.rs
        lib.rs
        metadata.rs
        mint.rs
        nft_core.rs
        royalty.rs
package.json

Meta Ads Smart Contract
==================

A [smart contract] written in [Rust] for an app initialized with [create-near-app]

Quick Start
===========

Before you compile this code, you will need to install Rust with [correct target]

Exploring The Code
==================

 - The main smart contract code lives in `src/lib.rs`. You can compile it with
   the `./compile` or `./build.sh` script.

How to deploy
==================

Each account on NEAR can have at most one contract deployed to it. If you've already created an account such as ` YOUR-NAME.testnet`, you can deploy your contract to `subaccount.YOUR-NAME.testnet`. Assuming you've already created an account on [NEAR Wallet], here's how to create `subaccount.YOUR-NAME.testnet`:

- Authorize NEAR CLI, following the commands it gives you:

      `near login`

- Create a subaccount (replace `YOUR-NAME` below with your actual account name):

      `near create-account subaccount.YOUR-NAME.testnet --masterAccount YOUR-NAME.testnet`

- Set contract to subaccount

      `near deploy --accountId subaccount.YOUR-NAME.testnet --wasmFile=./out/main.wasm `

Examples
==================

- Add creative

   `near call subaccount.YOUR-NAME.testnet make_creative '{"name": "My Creative", "content": "https://bafybeiftczwrtyr3k7a2k4vutd3amkwsmaqyhrdzlhvpt33dyjivufqusq.ipfs.dweb.link/goteam-gif.gi", "creative_id": $id, "nft_cid": $cid}' --accountId YOUR-NAME.testnet`

- Get a collection of creatives

   `near view subaccount.YOUR-NAME.testnet fetch_all_creatives`

- Get a creative by id

   `near view subaccount.YOUR-NAME.testnet fetch_creative_by_id '{"id": $id}'`

- Init presentation your creative

   `near call subaccount.YOUR-NAME.testnet do_agreement '{"playback_id": $pid, "creative_id": $сid, "adspot_id": $aid, "start_time": $s_time, "end_time": $e_time}' --accountId  YOUR-NAME.testnet --amount 0.1`

- Get a collection of presentations

   `near view subaccount.YOUR-NAME.testnet fetch_all_presentations`

- Get a presentation by id

   `near view subaccount.YOUR-NAME.testnet fetch_presentation_by_id '{"id": $id}'`

- Add AdSpot

   `near call subaccount.YOUR-NAME.testnet make_adspot '{"name": "Ad Spot", "adspot_id": $id, "price": $price}' --accountId YOUR-NAME.testnet `

- Get a collection of AdSpots

   `near view subaccount.YOUR-NAME.testnet fetch_all_adspots`

- Get a adspot by id

   `near view subaccount.YOUR-NAME.testnet fetch_adspot_by_id '{"id": $id}'`

- Transfer of funds to the publisher for presentation

   `near call subaccount.YOUR-NAME.testnet transfer_funds '{"playback_id": $pid}' --accountId  subaccount.YOUR-NAME.testnet`   

  [smart contract]: https://docs.near.org/docs/develop/contracts/overview
  [Rust]: https://www.rust-lang.org/
  [create-near-app]: https://github.com/near/create-near-app
  [correct target]: https://github.com/near/near-sdk-rs#pre-requisites
  [cargo]: https://doc.rust-lang.org/book/ch01-03-hello-cargo.html
Meta Ads
==================

This app was initialized with [create-near-app]

Quick Start
===========

To run this project locally:

1. Prerequisites: Make sure you've installed [Node.js] ≥ 12
2. Install dependencies: `yarn install`
3. Run the local development server: `yarn dev` (see `package.json` for a
   full list of `scripts` you can run with `yarn`)

Now you'll have a local development environment backed by the NEAR TestNet!

Go ahead and play with the app and the code. As you make code changes, the app will automatically reload.

Exploring The Code
==================

The "backend" code lives in the `/contract` and `nft-contract` folders. See the README there for more info.

Deploy
======

Install near-cli
-------------------------------------

[near-cli] is a command line interface (CLI) for interacting with the NEAR blockchain. It was installed to the local `node_modules` folder when you ran `yarn install`, but for best ergonomics you may want to install it globally:

    yarn install --global near-cli

Or, if you'd rather use the locally-installed version, you can prefix all `near` commands with `npx`

Ensure that it's installed with `near --version` (or `npx near --version`)

Troubleshooting
===============

On Windows, if you're seeing an error containing `EPERM` it may be related to spaces in your path. Please see [this issue](https://github.com/zkat/npx/issues/209) for more details.

  [create-near-app]: https://github.com/near/create-near-app
  [Node.js]: https://nodejs.org/en/download/package-manager/
  [jest]: https://jestjs.io/
  [NEAR accounts]: https://docs.near.org/docs/concepts/account
  [NEAR Wallet]: https://wallet.testnet.near.org/
  [near-cli]: https://github.com/near/near-cli
  [gh-pages]: https://github.com/tschaub/gh-pages
Meta Ads Smart Contract
==================

A [nft-contract] written in [Rust] for an app initialized with [nft-tutorial]

Quick Start
===========

Before you compile this code, you will need to install Rust with [correct target]

Exploring The Code
==================

 - The main smart contract code lives in `src/lib.rs`. You can compile it with
   the `./compile` or `./build.sh` script.

How to deploy
==================

Each account on NEAR can have at most one contract deployed to it. If you've already created an account such as `YOUR-NAME.testnet`, you can deploy your contract to `nft.YOUR-NAME.testnet`. Assuming you've already created an account on [NEAR Wallet], here's how to create `nft.YOUR-NAME.testnet`:

- Authorize NEAR CLI, following the commands it gives you:

      `near login`

- Create a subaccount for NFT contract (replace `YOUR-NAME` below with your actual account name):

      `near create-account nft.YOUR-NAME.testnet --masterAccount YOUR-NAME.testnet`

- Set NFT contract to subaccount

      `near deploy --accountId nft.YOUR-NAME.testnet  --wasmFile=./out/nft_contract.wasm`

- Initialize NFT contract

      `near call nft.YOUR-NAME.testnet new_default_meta '{"owner_id": "nft.YOUR-NAME.testnet"}' --accountId nft.YOUR-NAME.testnet`

- View Contracts Meta Data

      `near view nft.YOUR-NAME.testnet nft_metadata`

- Minting Token

      `near call nft.YOUR-NAME.testnet nft_mint '{"token_id": "token-1", "metadata": {"title": "Test Token 1", "description": "Test Token", "media": "https://bafybeiftczwrtyr3k7a2k4vutd3amkwsmaqyhrdzlhvpt33dyjivufqusq.ipfs.dweb.link/goteam-gif.gif"}, "receiver_id": "YOUR-NAME.testnet", "webdata": {"uri":"https://bafybeiftczwrtyr3k7a2k4vutd3amkwsmaqyhrdzlhvpt33dyjivufqusq.ipfs.dweb.link/goteam-gif.gif"}}' --accountId YOUR-NAME.testnet --amount 0.1`

- View NFT Information

      `near view nft.YOUR-NAME.testnet nft_token '{"token_id": "token-1"}'`

- Get the total supply of NFTs for a given owner

      `near view nft.YOUR-NAME.testnet nft_supply_for_owner '{"account_id": "OWNER-NAME.testnet"}'`

- Get all tokens for an owner 

      `near view nft.YOUR-NAME.testnet nft_tokens_for_owner '{"account_id": "OWNER-NAME.testnet", "limit": $limit}'`   

[nft-contract]: https://docs.near.org/es-ES/docs/tutorials/contracts/nfts/introduction
[Rust]: https://www.rust-lang.org/
[nft-tutorial]: https://github.com/near-examples/nft-tutorial
[correct target]: https://github.com/near/near-sdk-rs#pre-requisites
