Skip to content

Instantly share code, notes, and snippets.

@floatbeta
Created February 4, 2023 03:03
Show Gist options
  • Save floatbeta/c0cd321b8e3536a0ab7826d36769ce29 to your computer and use it in GitHub Desktop.
Save floatbeta/c0cd321b8e3536a0ab7826d36769ce29 to your computer and use it in GitHub Desktop.
Deploy fungible token on MoltenChain
-- Contract for creating a fungible token on MoltenChain
contract = function()
-- Token details
local name = "My Token"
local symbol = "MTK"
local website = "www.mytoken.com"
local image_url = "https://www.mytoken.com/logo.png"
local description = "This is my token for testing purposes."
local total_supply = 100000000
-- State management
local balances = {}
local total_created = 0
-- Contract functions
function init()
balances[system.getSender()] = total_supply
total_created = total_supply
end
function getName()
return name
end
function getSymbol()
return symbol
end
function getWebsite()
return website
end
function getImageURL()
return image_url
end
function getDescription()
return description
end
function getTotalSupply()
return total_created
end
function getBalance(address)
return balances[address] or 0
end
function transfer(to, amount)
local from = system.getSender()
if balances[from] and balances[from] >= amount and amount > 0 then
balances[from] = balances[from] - amount
balances[to] = (balances[to] or 0) + amount
return true
else
return false
end
end
-- Event for transfer
function Transfer(from, to, amount)
log(from, to, amount)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment