You can basically call any read/write calls from the contract. I have provided the "createToken" wrapper for you in the next section. If you need any more wrappers like "createToken", please let me know.
// import the sdk
import { bondContract } from 'test-mint.club-v2-sdk';
// read from contract
const data = bondContract.network('ethereum').read({
functionName: 'tokenCount',
args: [],
})
// write to the contract
const txReceipt = bondContract.network('ethereum').write({
functionName: 'someWriteFunction',
args: [...write function args],
onRequestSignature: () => {
console.log('signature');
},
onSigned: (txHash) => {
console.log(txHash);
},
onSuccess: (receipt) => {
console.log(receipt);
},
onError: (error) => {
console.dir(error);
},
})
// chain can be ['ethereum', 'optimism', 'arbitrum', 'avalanche', 'polygon', 'bnbchain', 'base', 'seoplia']
// 1 | 10 | 42161 | 43114 | 137 | 56 | 8453 | 11155111
// or you could also pass chainId
const data = bondContract.network(1).read({
functionName: 'tokenCount',
args: [],
})
Creating tokens
Below is the example code for creating a token.
// creating a new token
await bondContract.network('sepolia').createToken({
name: 'Baby Token',
symbol: 'BABY',
mintRoyalty: 1, // 1%
burnRoyalty: 1.5, // 1.5%
reserveToken: {
address: "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14", // WETH
decimals: 18,
},
stepData: [
// creator allocation is determined if first step price is 0
// here the creator will get 10,000 tokens for free
{ rangeTo: 10_000, price: 0 },
{ rangeTo: 100_000, price: 2 },
{ rangeTo: 200_000, price: 3 },
{ rangeTo: 500_000, price: 4 },
{ rangeTo: 1_000_000, price: 5 },
{ rangeTo: 2_000_000, price: 7 },
{ rangeTo: 5_000_000, price: 10 },
// max supply is determined by the last step rangeTo
// here, the max supply is 10,000,000
{ rangeTo: 10_000_000, price: 15 },
],
onError: (error) => {
console.dir(error);
toast.error(`Error creating token - ${error.message}`);
},
onSuccess: (txHash) => {
console.log(txHash);
toast.success(`Token created - ${txHash}`);
},
onRequestSignature: () => {
console.log("signature");
toast(`Please sign the transaction.`);
},
onSigned: (txHash) => {
console.log(txHash);
toast.success(`Transaction signed - ${txHash}`);
},
});
Read calls
You can read from the contract using the read method. It returns a promise with the result.
// reading from contract on a specific network
import { bondContract } from 'test-mint.club-v2-sdk';
const tokenCount = bondContract.network('ethereum').read({
functionName: 'tokenCount',
args: [],
});
// you can also pass chainId
const tokenCount = bondContract.network(1).read({
functionName: 'tokenCount',
args: [],
});
console.log(tokenCount); // some big number
Ethereum token count: 0
Extra ✨
import { bondContract } from 'test-mint.club-v2-sdk';
// write call should automatically prompt the user to connect wallet & switch chains
const txReceipt = await bondContract.network('sepolia').write({ ... });
// you could also pass the connected address
const txReceipt = await bondContract
.network('sepolia')
.withAccount('0xdeadbeef')
.write({ ... });
// ... or a different provider than window.ethereum
const withOKX = await bondContract
.network('sepolia')
.withProvider(window.okex)
.write({ ... });
const otherProvider = await bondContract
.network('sepolia')
.withProvider(new Web3Provider(...))
.write({ ... });
// ... or with a private key
const txReceipt = await bondContract
.network('sepolia')
.withPrivateKey('0xdeadbeef')
.write({ ... });
- If you are unsure about what to pass to the read/write function, please refer to the the contract repo
- You can see all the read/write functions on etherscan