.smartContracts
Provides endpoints to smart contracts and smart contract related data
Retrieve a list of all deployed smart contracts associated with your account.
import { NorthstakeApi } from "@northstake/northstakeapi";
const api = new NorthstakeApi("apiKey", "privateKey");
const { body } = await api.smartContracts.getSmartContracts();
for (const contract of body.smartContracts) {
console.log(`
Contract Address: ${contract.address}
Contract Name: ${contract.name}
Asset: ${contract.asset}
Contract Type: ${contract.type}
Deployment Date: ${contract.deployedAt}
Deployed By: ${contract.deployedBy}
Status: ${contract.status}
Validator Providers: ${contract.validatorProviders.join(", ")}
Whitelisted Depositors:
${contract.whitelistedDepositors.map(depositor => `
- Address: ${depositor.address}
Transaction Hash: ${depositor.transactionHash}
Timestamp: ${depositor.timeStamp}
`).join("\n")}
`);
}
Retrieve blocks mined by a specific smart contract by providing its address.
import { NorthstakeApi } from "@northstake/northstakeapi";
const api = new NorthstakeApi("apiKey", "privateKey");
const contractAddress = "0xYourContractAddress";
const { body } = await api.smartContracts.getSmartContractMinedBlocks({
contractAddress, // Required
page: 1, // Optional
limit: 10, // Optional
startDate: new Date("2024-01-01"), // Optional
endDate: new Date("2024-12-31"), // Optional
});
for (const block of body.minedBlocks) {
console.log(`
Block Number: ${block.number}
Block Reward: ${block.blockReward}
Timestamp: ${block.timestamp}
Address: ${block.address}
`);
}
Retrieve transactions related to a specific smart contract by providing its address.
import { NorthstakeApi } from "@northstake/northstakeapi";
const api = new NorthstakeApi("apiKey", "privateKey");
const contractAddress = "0xYourContractAddress";
const { body } = await api.smartContracts.getSmartContractTransactions({
contractAddress, // Required
page: 1, // Optional
limit: 10, // Optional
startDate: new Date("2024-01-01"), // Optional
endDate: new Date("2024-12-31"), // Optional
});
for (const transaction of body.transactions) {
console.log(`
Block Number: ${transaction.blockNumber}
Timestamp: ${transaction.timestamp}
Hash: ${transaction.hash}
Nonce: ${transaction.nonce}
Block Hash: ${transaction.blockHash}
Transaction Index: ${transaction.transactionIndex}
From Address: ${transaction.fromAddress}
To Adress: ${transaction.toAddress}
Value in ETH: ${transaction.value}
Gas Price: ${transaction.gasPrice}
Gas Used: ${transaction.gasUsed}
Transaction Fee: ${transaction.transactionFee}
Is Error: ${transaction.isError}
Input: ${transaction.input}
Input Decoded: ${transaction.inputDecoded}
Function Name: ${transaction.functionName}
Function Signature: ${transaction.functionSignature}
FunctionArgsDecoded: ${transaction.functionArgsDecoded}
`);
for (const internalTransaction of transaction.internalTransactions) {
console.log(`
Internal transaction
Block Number: ${internalTransaction.blockNumber}
Timestamp: ${internalTransaction.timestamp}
Transaction Hash: ${internalTransaction.hash}
From Address: ${internalTransaction.fromAddress}
To Address: ${internalTransaction.toToaddress}
Value in ETH: ${internalTransaction.value}
Is Error: ${internalTransaction.isError}
`);
}
}
Updated 14 days ago