treasure-contracts 0.1.1-dev.e594441.0
Install from the command line:
Learn more about npm packages
$ npm install @treasure-chess/treasure-contracts@0.1.1-dev.e594441.0
Install via package.json:
"@treasure-chess/treasure-contracts": "0.1.1-dev.e594441.0"
About this version
Smart Contracts and Subgraphs for Treasure Chess
This package includes resources for interacting with the Treasure Chess contracts. We've provided the Application Binary Interface (ABI), which can be used as follows:
Install the package
yarn add @treasure-chess/treasure-contracts
Import the package, and use ethers.js
to create the contract
import treasureArtifact from "@treasure-chess/treasure-contracts/artifacts/contracts/Treasure.sol/Treasure.json";
import { Contract } from "@ethersproject/contracts";
import { JsonRpcProvider } from "@ethersproject/providers";
const treasureAbi = treasureArtifact.abi;
const rpcProvider = new JsonRpcProvider(process.env.MATIC_RPC);
const treasureContract = new Contract(
"0x...."; // See our docs for the address
treasureAbi,
rpcProvider
);
const tx = await treasureContract.balanceOf("0x...")
To get a local copy up and running follow these simple steps.
You also need a .env
file with the following items:
NOTE: This section needs updating.
-
ROPSTEN_PRIVATE_KEY
: A private key (account which will deploy) for testing. -
INFURA_API_KEY
: An infura api key which you can obtain from infura. -
FORWARDER_ADDRESS
: The opengsn forwarder address - this will vary based on which network you are deploying/testing on or if you want to deploy your own forwarder.
To run tests, first compile the project with yarn compile
and then yarn test
.
To deploy the contracts, simply call yarn deploy --network <NETWORK>
. Keep in mind, you must add this network to the hardhat.config.ts
file with the necessary information for this to work.
We adhere to EIP 1822 and EIP 1967 implementations using Open Zeppelin. In order to find the address of the logic contract, you can follow these steps:
- Navigate to https://etherflow.quiknode.io/ (thanks to Quicknode for providing this powerful tool!) and enter your RPC, eg. https://rpc-mainnet.matic.network
- Select the
ethers
library and the calleth_getStorageAt
- Enter the address for the proxy contract (this is the one you interact with), and a storage slot of
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
. The result should be the address for the logic contract.
Interface for using a token
function tokenListItem(uint tokenId, uint price, uint duration) public
function tokenUnlistItem(uint tokenId) public
function tokenInstantBuy(uint tokenId) public
function safeTransferFrom(address from, address to, uint256 tokenId)
Make meta transaction calls calling the functions normally, and getting end user to sign them normally. The web3 provider that is created knows where the paymaster + relayer contracts are deployed, and actually sends the transaction through the relayer instead of straight to the Treasure or Treasure Market smart contracts.
GSN example: https://docs.opengsn.org/javascript-client/getting-started.html#adding-gsn-support-to-existing-app
To test upgrading the contract, you first need to deploy the Treasure
and TreasureMarket
contracts and copy the addresses over to your .env
file under TREASURE_ADDRESS
and TREASURE_MARKET_ADDRESS
.
The current setup upgrades the contract to TreasureUpgraded.sol
and TreasureMarketUpgraded.sol
, but you can modify the upgradeContracts
function in scripts/helpers.ts
to upgraded to any contract (change value passed to getContractFactory
).
To upgrade the contracts, use yarn upgrade-contracts --network <NETWORK>
.
Example tests of GSN enabled contract: https://github.com/qbzzt/opengsn/blob/master/01_SimpleUse/test/testcontracts.js
Example JS in UI for GSN transactions: https://github.com/qbzzt/opengsn/blob/master/01_SimpleUse/ui/etherless.js
Use the deployed relayer and our Paymaster. Check above for relayer addresses for each network.
import { RelayProvider } from "@opengsn/provider";
import Treasure from "/path/to/artifact";
import PayMaster from "/path/to/artifact";
import TreasureMarket from "/path/to/artifact";
const conf = {
Treasure: "0xabc123",
TreasureMarket: "0x1a2b3c",
paymaster: "0x123abc",
gasPrice: 1000000000, // 1 Gwei
};
const web3Provider = window.ethereum; // Change for node-js environment
const gsnProvider = new gsn.RelayProvider(web3Provider, {
forwarderAddress: conf.forwarder, // Needs clarification
paymasterAddress: conf.paymaster,
verbose: false, // logging
});
await gsnProvider.init();
gsnProvider = new ethers.providers.Web3Provider(gsnProvider);
userAddr = gsnProvider.origProvider.selectedAddress;
Make a GSN contract call
const gsnContractCall = async () => {
await connect2Gsn(); // Needs clarification
await provider.ready;
// Using Treasure transferFrom as an example
const treasureContract = await new ethers.Contract(
treasureAddress,
treasureAbi,
provider.getSigner(userAddr)
);
const tx = await treasureContract.transferFrom();
console.log(`Transaction ${tx.hash} sent`);
const receipt = await tx.wait();
console.log(`Mined in block: ${receipt.blockNumber}`);
};
Details
- treasure-contracts
- treasure-chess
- over 2 years ago
- MIT
- 28 dependencies
Assets
- treasure-contracts-0.1.1-dev.e594441.0-npm.tgz
Download activity
- Total downloads 0
- Last 30 days 0
- Last week 0
- Today 0