Skip to main content

Best Practices

Network Selection​

Use Testnets for Development​

  • Test on Sepolia, Amoy, or other testnets first
  • Consider gas costs - different networks have different cost structures
  • Ensure your contract is deployed on the target network

Error Handling​

Common Issues​

Invalid contract address

  • Ensure the address is a valid Ethereum address
  • Verify the contract is deployed on the specified network

Invalid ABI format

  • Use formatted ABI strings, not raw ABI objects
  • Validate ABI syntax before importing

Permission denied

  • Ensure you have Admin or Editor role for the project
  • Check your API access token and project API key

Network not supported

  • Verify the network ID is in the supported networks list
  • Contact support if you need additional network support

Complete Implementation Example​

Here's a complete example showing the full workflow from import to function management:

import { ContractApi } from '@kyuzan/mountain-public-api-client';
import { formatAbi } from 'abitype';

async function completeContractSetup() {
const contractApi = new ContractApi();

try {
// 1. Prepare ABI (if you have raw ABI)
const rawAbi = [
{
inputs: [
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
name: 'mint',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{ name: 'to', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
name: 'transfer',
outputs: [{ name: '', type: 'bool' }],
stateMutability: 'nonpayable',
type: 'function',
},
{
anonymous: false,
inputs: [
{ indexed: true, name: 'from', type: 'address' },
{ indexed: true, name: 'to', type: 'address' },
{ indexed: false, name: 'value', type: 'uint256' },
],
name: 'Transfer',
type: 'event',
},
];

const formattedAbi = formatAbi(rawAbi);

// 2. Import the contract
const importResult = await contractApi.importContract({
networkId: 1,
address: '0x1234567890123456789012345678901234567890',
formattedAbi: formattedAbi,
});

console.log('Contract imported:', importResult.contract);

// 3. Activate specific functions
const mintFunction = await contractApi.activateContractFunction({
contractId: importResult.contract.id,
formattedAbiFunction: 'function mint(address to, uint256 amount)',
});

const transferFunction = await contractApi.activateContractFunction({
contractId: importResult.contract.id,
formattedAbiFunction: 'function transfer(address to, uint256 amount) returns (bool)',
});

console.log('Functions activated:', {
mint: mintFunction.contractActivatedFunction,
transfer: transferFunction.contractActivatedFunction,
});

// 4. Verify activated functions
const activatedFunctions = await contractApi.getContractActivatedFunctions({
contractId: importResult.contract.id,
});

console.log('All activated functions:', activatedFunctions.contractActivatedFunctions);

return {
contract: importResult.contract,
activatedFunctions: activatedFunctions.contractActivatedFunctions,
};
} catch (error) {
console.error('Contract setup failed:', error.message);
throw error;
}
}

// Usage
completeContractSetup()
.then((result) => console.log('Setup complete:', result))
.catch((error) => console.error('Setup failed:', error));

Next Steps​