Skip to content

permaweb/atomic-token

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Atomic Token Contract

The Atomic Token Contract is designed as a contract for tradeable tokens that can be deployed alongside any digital asset. This contract incorporates both the SmartWeave Token (PST) Spec and the Foreign Call Protocol 2.0 (FCP2) Spec, enabling seamless integration and enhanced functionality.

Goal

The goal of this contract is to create a permanent atomic token contract that is complete and flexible for both the NFT use case and the Token use case. This contract contains a constructor that will default the name, ticker, and balances properties if the creator chooses not to define those properties.

Contract Source TX

You can use this source tx to deploy your atomic assets.

Of9pi--Gj7hCTawhgxOwbuWnFI1h24TTgO5pw8ENJNQ

Example (Dispatch and Warp)

In this example, the application is using the browser, with the dispatch function and the warp register function. This example is great for assets under 100kb.

import { DeployPlugin } from "warp-contracts-plugin-deploy";
import { WarpFactory } from "warp-contracts";
import Arweave from "arweave";

const arweave = Arweave.init({});
const warp = WarpFactory.forMainnet().use(new DeployPlugin());

export async function create(data, tags) {
  const tx = arweave.createTransaction(data);
  tags.forEach((t) => {
    tx.addTag(t.name, t.value);
  });
  // Publish as Atomic Token, using defaults
  tx.addTag("App-Name", "SmartWeaveContract");
  tx.addTag("App-Version", "0.3.0");
  tx.addTag("Contract-Src", "Of9pi--Gj7hCTawhgxOwbuWnFI1h24TTgO5pw8ENJNQ");
  tx.addTag("Init-State", JSON.stringify({}));
  tx.addTag("Contract-Manifest", '{"evaluationOptions":{"sourceType":"redstone-sequencer","allowBigInt":true,"internalWrites":true,"unsafeClient":"skip","useConstructor":true}}')
  const result = await arweaveWallet.dispatch(tx);
  await warp.register(tx.id, "node2");
  return result;
}

You will notice that the state is blank, this is because the constructor will default the core props of the contract. It will set the signer as the owner with a balance of one, and default the name and ticker properties.

{
  "name": "Atomic Asset",
  "ticker": "AA",
  "balances": {
    "[action.caller]": 100
  },
  "claimable": []
}

If you would like to override these defaults, just send your initial state object as the state.

For more examples, check out the Permaweb Cookbook - https://cookbook.g8way.io

IMPORTANT

To successfully read this contract, you need to make sure that useConstructor is set to true.

import { WarpFactory } from "warp-contracts";

const warp = WarpFactory.forMainnet();

async function main() {
  const result = await warp
    .contract(process.argv[2])
    .setEvaluationOptions({
      allowBigInt: true,
      internalWrites: true,
      unsafeClient: "skip",
      useConstructor: true,
    })
    .readState();

  console.log(result.cachedValue.state);
}

main();

About

Atomic Token Tradeable Contract

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors