Skip to content

NearNet/nearapps-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nearapps Contracts

Execute Contract

Interface

methods:

  • new
  • execute
  • add_owner
  • remove_owner
  • is_owner
  • get_owners
  • verify_msg
  • verify_hashed_msg

Initialization

method: new

Parameters
  • owner_id: string - the account_id of who will own the contract
Returns

Has no returns.

Sample
{
}

Execution of a Proxied Contract Call

method: execute

Parameters
  • context: the call context.
    • contract_call: the contract call context.
      • contract_id: string - the contract's AccountId that is being called.
      • method_name: string - the name of the method being called.
      • args: string - the arguments for the method that is being called.
    • tag_info: the tags information.
      • app_id: string - app tag.
      • action_id: string - action number.
      • user_id: string - user account_id tag.
Returns
  • result - the same return that contract_id's method method_name with args would return.
Sample
{
  "context": {
    "contract_call": {
      "contract_id": "nft.naps.testnet",
      "method_name": "nft_transfer_from",
      "args": "\"token_id\": \"1\", \"sender_id\": \"my-account.testnet\", \"receiver_id\": \"my-friend.testnet\", \"approval_id\": \"4711\""
    }
  }
}

Owners Management

methods:

  • add_owner
  • remove_owner
  • is_owner
  • get_owners
Add Owner

method: add_owner

Parameters
  • owner_id: string - the account_id of who will also own the contract
Returns
  • added: boolean - whether the account was newly added as an owner.
Sample
{
}
Remove Owner

method: remove_owner

Parameters
  • owner_id: string - the account_id of who will stop owning the contract
Returns
  • removed: boolean - whether the account was just removed as an owner.
Sample
{
}
Check Owner

method: is_owner

Parameters
  • owner_id: string - the account_id which the owning status is being checked
Returns
  • is_owner: boolean - whether the account is an owner.
Sample
{
}
Get Owners

method: get_owner

Parameters

No parameters required.

Returns
  • owners: string[] - list of account_ids of the owners.
Sample
{
}

Verification of a Message

method: verify_msg

Parameters
  • sign: string - the signature, in base58. Can be a Ed25519 or a Secp256k1 signature.
  • pubkey: string - the public key, in base58 with an optional {header}: as prefix. Can be a Ed25519 or a Secp256k1 public key. On a missing prefix, ed25519: is assumed.
  • msg: string - the message. It will be hashed internally by the contract.
Returns
  • is_match: boolean - whether the sha256 hash of the msg matched the pubkey on the sign.
Sample
{
  "sign": "26gFr4xth7W9K7HPWAxq3BLsua8oTy378mC1MYFiEXHBBpeBjP8WmJEJo8XTBowetvqbRshcQEtBUdwQcAqDyP8T",
  "pubkey": "ed25519:AYWv9RAN1hpSQA4p1DLhCNnpnNXwxhfH9qeHN8B4nJ59",
  "msg": "message"
}

Verification of a Prehashed Message

method: verify_hashed_msg

Parameters
  • sign: string - the signature, in base58. Can be a Ed25519 or a Secp256k1 signature.
  • pubkey: string - the public key, in base58 with an optional {header}: as prefix. Can be a Ed25519 or a Secp256k1 public key. On a missing prefix, ed25519: is assumed.
  • msg_hash: number[] - the message hash, in a 32-sized array of bytes, resulted from a sha256 hash of them message.
Returns
  • is_match: boolean - whether the msg_hash matched the pubkey on the sign.
Sample
{
  "sign": "26gFr4xth7W9K7HPWAxq3BLsua8oTy378mC1MYFiEXHBBpeBjP8WmJEJo8XTBowetvqbRshcQEtBUdwQcAqDyP8T",
  "pubkey": "ed25519:AYWv9RAN1hpSQA4p1DLhCNnpnNXwxhfH9qeHN8B4nJ59",
  "msg_hash": [171, 83, 10, 19, 228, 89, 20, 152, 43, 121, 249, 183, 227, 251, 169, 148, 207, 209, 243, 251, 34, 247, 28, 234, 26, 251, 240, 43, 70, 12, 109, 29]
}

Wallet Creation

  • testnet: ``
  • mainnet: ``

Interface

methods:

  • new
  • create_account

Initialization

method: new

Parameters
  • owner_id: string - owner account id that will be allowed to make other calls into this contract
Returns

Has no returns.

Sample
{
}

Account Creation

note: not tested.

method: create_account

Parameters
  • new_account_id: string - the account_id that is being created
  • new_public_key: optional string - the new account owner public key, in base58 with an optional {header}: as prefix. Can be a Ed25519 or a Secp256k1 public key. On a missing prefix, ed25519: is assumed. This value may be generated by the user. If missing, defaults to the transaction signer's public key.
Returns
  • account_created: boolean - whether the account was successfully created.
Sample
{
}

NFT

Contract Address:

Interface

methods:

  • new
  • new_default_meta
  • nft_mint
  • nft_transfer
  • nft_transfer_call
  • nft_token
  • nft_approve
  • nft_revoke
  • nft_revoke_all
  • nft_is_approved
  • nft_total_supply
  • nft_tokens
  • nft_supply_for_owner
  • nft_tokens_for_owner
  • nft_metadata
  • nft_series_create
  • nft_series_mint
  • nft_series_get
  • nft_series_get_minted_tokens_vec
  • nft_series_set_mintable
  • nft_series_set_capacity

Initialization

method: new

Parameters
  • owner_id: string - the account_id of who will own the contract
  • metadata: object - the standard nft metadata
    • spec: stirng - eg. "nft-1.0.0"
    • name: string - eg. "Mosaics"
    • symbol: string - eg. "MOSIAC"
    • icon: optional string - data URL
    • base_uri: optional string - centralized gateway known to have reliable access to decentralized storage assets referenced by reference or media URLs
    • reference: optional string - URL to a JSON file with more info
    • reference_hash: optional string - base64-encoded sha256 hash of JSON from reference field. Required if reference is included.
Returns

Has no returns.

Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample

Initialization with a default Meta

method: new_default_meta

Parameters
  • owner_id: string - the account_id of who will own the contract
Returns

Has no returns.

Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample

NFT Minting

method: nft_mint

Parameters
  • token_id: string - the name of the token. Cannot contain the series delimiter (:).
  • token_owner_id: string - the account_id of who will receive the token.
  • token_metadata: object - the standard nft token metadata.
    • title: optional string - the title of the token, eg. "Arch Nemesis: Mail Carrier" or "Parcel #5055".
    • description: optional string - free-form description.
    • media: optional string - URL to associated media, preferably to decentralized, content-addressed storage.
    • media_hash: optional stirng - Base64-encoded sha256 hash of content referenced by the media field. Required if media is included.
    • copies: optional string - number of copies of this set of metadata in existence when token was minted.
    • issued_at: optional string - ISO 8601 datetime when token was issued or minted.
    • expires_at: optional string - ISO 8601 datetime when token expires.
    • starts_at: optional string - ISO 8601 datetime when token starts being valid. -updated_at: optional string - ISO 8601 datetime when token was last updated.
    • extra: optional string - anything extra the NFT wants to store on-chain. Can be stringified JSON.
    • reference: optional string - URL to an off-chain JSON file with more info.
    • reference_hash: optional string - Base64-encoded sha256 hash of JSON from reference field. Required if reference is included.
Returns
  • token: object - the standard nft token information.
Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample

Standard NFT Operations

methods:

  • nft_transfer
  • nft_transfer_call
  • nft_token
  • nft_resolve_transfer
  • nft_approve
  • nft_revoke
  • nft_revoke_all
  • nft_is_approved
  • nft_total_supply
  • nft_tokens
  • nft_supply_for_owner
  • nft_tokens_for_owner
  • nft_metadata
Transfer

method: nft_transfer

Parameters
  • token_id: string - the token id to give allowance on.
  • receiver_id: string - the account to allow token transfer.
  • approval_id: optional number - the approval id from nft_approve_from.
  • memo: optional string.
Sample
{
  "token_id": "1",
  "receiver_id": "my-friend.testnet"
}
Returns
  • success: bool - was the transfer successful or not
Nearapps API Sample
curl --location --request POST 'https://api.nearapps.net/testnet/v1/execute' \
--header 'x-api-key: <api key>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "{\"contract_id\":\"nft.naps.testnet\",\"method_name\":\"nft_transfer_from\",\"args\": \"{\"token_id\":\"1\",\"sender_id\":\"my-account.testnet\", \"receiver_id\":\"my-friend.testnet\"}\",
    "signed": {
        "signature": "4FJecZiY22ReWiJHxCSjDw71Jyd8WVgkkeNfH1Zj21uhQEV1c7QQ4bQYc7QMgH3Tcz5LxYJMxPYuHoETN8i4sQNq",
        "publicKey": "ed25519:D5d84XpgHtTUHwg1hbvT3Ljy6LpeLnJhU34scBC1TNKp"
    }
}'
Transfer Call

method: nft_transfer_call

Parameters
  • token_id: string - the token id to give allowance on
  • receiver_id: string - the account to allow token transfer
Sample
{
  "token_id": "1",
  "receiver_id": "my-friend.testnet"
}
Returns
  • success: bool - was the transfer successful or not
Nearapps API Sample
curl --location --request POST 'https://api.nearapps.net/testnet/v1/execute' \
--header 'x-api-key: <api key>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "{\"contract_id\":\"nft.naps.testnet\",\"method_name\":\"nft_transfer_from\",\"args\": \"{\"token_id\":\"1\",\"sender_id\":\"my-account.testnet\", \"receiver_id\":\"my-friend.testnet\"}\",
    "signed": {
        "signature": "4FJecZiY22ReWiJHxCSjDw71Jyd8WVgkkeNfH1Zj21uhQEV1c7QQ4bQYc7QMgH3Tcz5LxYJMxPYuHoETN8i4sQNq",
        "publicKey": "ed25519:D5d84XpgHtTUHwg1hbvT3Ljy6LpeLnJhU34scBC1TNKp"
    }
}'
Approval

method: nft_approve

Parameters
  • token_id: string - the token id to give allowance on
  • account_id: string - the account to allow token transfer
  • msg: optional string.
Sample
{
  "token_id": "1",
  "account_id": "my-friend.testnet"
}
Returns
  • approval_id: the id of the approval
Nearapps API Sample
curl --location --request POST 'https://api.nearapps.net/testnet/v1/execute' \
--header 'x-api-key: <api key>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "{\"contract_id\":\"nft.naps.testnet\",\"method_name\":\"nft_approve_from\",\"args\": \"{\"token_id\":\"1\",\"account_id\":\"my-friend.testnet\"}\"}",
    "sender": "my-account.testnet",
    "signed": {
        "signature": "4FJecZiY22ReWiJHxCSjDw71Jyd8WVgkkeNfH1Zj21uhQEV1c7QQ4bQYc7QMgH3Tcz5LxYJMxPYuHoETN8i4sQNq",
        "publicKey": "ed25519:D5d84XpgHtTUHwg1hbvT3Ljy6LpeLnJhU34scBC1TNKp"
    }
}'
Check Approval

method: nft_is_approved

Parameters
  • token_id: string - the token id to check allowance on
  • approved_account_id: string.
  • approval_id: optional number.
Sample
{
}
Returns
  • is_approved: boolean - whether it is approved.
Nearapps API Sample
Revoke

method: nft_revoke

Parameters
  • token_id: string - the token id to revoke allowance on
  • account_id: string - the account to disallow token transfer
Sample
{
  "token_id": "1",
  "account_id": "my-friend.testnet"
}
Returns

Has no returns.

Nearapps API Sample
curl --location --request POST 'https://api.nearapps.net/testnet/v1/execute' \
--header 'x-api-key: <api key>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "{\"contract_id\":\"nft.naps.testnet\",\"method_name\":\"nft_revoke_from\",\"args\": \"{\"token_id\":\"1\",\"account_id\":\"my-friend.testnet\"}\"}",
    "sender": "my-account.testnet",
    "signed": {
        "signature": "4FJecZiY22ReWiJHxCSjDw71Jyd8WVgkkeNfH1Zj21uhQEV1c7QQ4bQYc7QMgH3Tcz5LxYJMxPYuHoETN8i4sQNq",
        "publicKey": "ed25519:D5d84XpgHtTUHwg1hbvT3Ljy6LpeLnJhU34scBC1TNKp"
    }
}'
Revoke All

method: nft_revoke

Parameters
  • token_id: string - the token id to revoke allowance on
Sample
{
  "token_id": "1"
}
Returns

Has no return.

Nearapps API Sample

NFT Series Operations

methods:

  • nft_series_create
  • nft_series_mint
  • nft_series_get
  • nft_series_get_minted_tokens_vec
  • nft_series_set_mintable
  • nft_series_set_capacity
NFT Series Creation

method: nft_series_create

Parameters
  • name: string - the name of the token series
  • capacity: string - the maximum number of the of tokens that can be minted
  • creator: string - the account_id of the creator, used for informing
Returns
  • series_id: string - a number representing the id of the created series.
Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample
NFT Series Token Minting

method: nft_series_mint

Parameters
  • series_id: string - the series id number
  • token_owner_id: string - the account_id of who will receive the token.
  • token_metadata: optional object - the standard nft token metadata.
Returns
  • token: object - the standard nft token information.
Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample
NFT Series Query

method: nft_series_get

Parameters
  • series_id: string - the series id number
Returns
  • series: object - nft series information.
    • id: string - the series id number,
    • name: string
    • creator: string - the account_id of the creator
    • len: string - the number of minted tokens
    • capacity: string - the number of how many tokens can be minted
    • is_mintable: boolean - whether the series can be minted
Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample
NFT Series Token List

method: nft_series_get_minted_tokens_vec

Parameters
  • series_id: string - the series id number
Returns
  • token_ids: string[] - a list containing the token_id number that were minted under the series.
Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample
NFT Series Set Mintable

method: nft_series_set_mintable

Parameters
  • series_id: string - the series id number.
  • is_mintable: boolean - choose whether it will be mintable or not.
Returns

Has no returns.

Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample
NFT Series Set Capacity

method: nft_series_set_capacity

Parameters
  • series_id: string - the series id number.
  • capacity: string - choose the number of what the capacity will be.
Returns

Has no returns.

Sample
{
}
Reference Metadata JSON Sample
{
}
Nearapps API Sample

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published