🪙 Tokens

Token creation and transactions in less than 50 lines of code.

Example of a smart contract that would create a Token and allow transactions:

// TACOS TOKEN

var input =
// INPUT
  {
    to: "",
    amount: 0,
  };
// INPUT END

input.from = block.by;

var fromBalance = get({ scope: contract.hash, name: "balance/" + input.from });
var initialized = get({ scope: contract.hash, name: "initialized" });

if (fromBalance && fromBalance - input.amount >= 0) {
  var toBalance = get({ scope: contract.hash, name: "balance/" + input.to }) || 0;

  fromBalance = fromBalance - input.amount;
  toBalance = toBalance + input.amount;

  put({
    scope: contract.hash,
    name: "balance/" + input.from,
    value: fromBalance,
  });
  put({ scope: contract.hash, name: "balance/" + input.to, value: toBalance });
  
} else {
  if(initialized) {
    throw Error("Not enough balance for transfer")
  }
}


// INITIALIZATION
if (!initialized) {
  put({ scope: contract.hash, name: "balance/" + block.by, value: 1000 });
  put({ scope: contract.hash, name: "initialized", value: true });
}

This creates the "taco" token and adds 1000 tokens to the entity that created it.

To generate transactions of the token, the smart-contract would be used in the following form:

// IMPORT e0d24ef53c4ea3e...9309790106ee9f53
{
  to: "jhon",
  amount: 20
}

Last updated