Skip to content

Instantly share code, notes, and snippets.

@t8
Forked from samcamwilliams/Physical-Asset-NFT.js
Last active April 28, 2022 03:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t8/6b63fa2b197bb1732519b5c1e6ef09bb to your computer and use it in GitHub Desktop.
Save t8/6b63fa2b197bb1732519b5c1e6ef09bb to your computer and use it in GitHub Desktop.
A Verto-compatible SmartWeave contract for NFTs.
export function handle (state, action) {
let owner = state.owner
const input = action.input
const caller = action.caller
const contact = action.contact
if (input.function === 'transfer') {
const target = input.target
if (!target || (caller === target)) {
throw new ContractError('Invalid target for transfer')
}
if (caller !== owner) {
throw new ContractError(`Caller does not own the item`)
}
owner = target
return { state }
}
if (input.function === 'balance') {
const target = input.target
const ticker = state.ticker
if (typeof target !== 'string') {
throw new ContractError('Must specificy target to get balance for')
}
return { result: { target, ticker, balance: (target === owner) ? 1 : 0 } }
}
throw new ContractError(`No function supplied or function not recognised: "${input.function}"`)
}
@t8
Copy link
Author

t8 commented Feb 11, 2021

Example initial state:

{
    "ticker": "OWOCEAN",
    "owner": "vLRHFqCw1uHu75xqB4fCDW-QxpkpJxBtFD9g4QYUbfw",
    "data": "00gT33gZpgWK4HMS0AuEy8OXC5_xyQjyJCsX6ps0iuM"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment