Smart Contract Quick Start¶
Compile and test a contract locally before considering deployment. The public testnet can reset, and test keys must remain separate from mainnet keys.
Prerequisites¶
- Node.js for the executable client example
- Your contract toolchain and a compiled
.wasmfile for deployment - A dedicated funded testnet account
The canonical public endpoint is:
https://testnet.koinosfoundation.org/jsonrpc
Safe deployment configuration¶
export function deploymentConfig(env = process.env) {
return {
network: "testnet",
rpcUrl: "https://testnet.koinosfoundation.org/jsonrpc",
wasmFile: env.WASM_FILE ?? "build/release/contract.wasm",
privateKeySource: "TESTNET_WIF environment variable",
broadcast: env.BROADCAST === "true",
};
}
View complete file · Run example
The example records the key's environment-variable name, never the key itself,
and defaults to broadcast: false. A deployment tool must additionally load
the compiled bytecode and ABI, validate the current chain ID, and obtain
explicit approval before broadcast.
Read a deployed token contract¶
export async function readTokenMetadata(
contractId = TESTNET_KOIN,
fetchImpl = fetch
) {
const url =
`https://testnet.koinosfoundation.org/v1/token/` +
`${encodeURIComponent(contractId)}/info`;
const response = await fetchImpl(url, {
headers: { accept: "application/json" },
});
if (!response.ok) throw new Error(`Testnet API HTTP ${response.status}`);
return response.json();
}
View complete file · Run example
The complete Node.js program reads the current testnet KOIN metadata and prints the dry-run deployment defaults. It requires no key and changes no state.
Verify¶
npm install
npm test
npm start
For your own contract, replace the default contract ID only after deployment and update the read logic to match the deployed ABI.