-
-
Save t8/6b63fa2b197bb1732519b5c1e6ef09bb to your computer and use it in GitHub Desktop.
A Verto-compatible SmartWeave contract for NFTs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example initial state: