LogoLogo
WebDiscordTelegramBlog
  • Source Protocol
    • Introduction
    • Vision
    • Business Solutions
    • DeFi-as-a-Service
    • Ecosystem Overview
    • JOIN SOURCE
  • SOURCE - $SOURCE
    • Tokenomics
    • Features Part 1
    • Features Part 2
    • Why Guardian Nodes?
    • Source Swap
    • Airdrop
    • Claim Source-Drop
    • How to IBC Transfer
    • Community
  • SourceSwap - On Chain DEX
    • Connect and Deposit
    • Swap
    • Manage Liquidity
  • Governance
    • Before Submitting a Proposal
    • Submitting a Proposal (CLI)
  • COMMAND-LINE INTERFACE (CLI)
    • Introduction
    • Useful CLI Commands
  • SMART CONTRACTS & SOURCED DEVELOPMENT
    • Sourced Local Dev Setup
    • Source Chain Testnet Setup
      • Testnet Links
    • Smart Contracts with COSMWASM
    • CW-20/ERC-20 Tutorial
      • Installation
      • Download, Compile, Store
      • Initialize the Contract
      • Query and run commands
    • CW1 Tutorial
      • Installation
      • Download, Compile, Store
      • Initialize the Contract
      • Query commands
      • Execute commands
  • Nodes & Validators
    • Mainnet: Sourced Installation and Setup
    • Setting up Cosmovisor
    • Mainnet Setup and Tooling
    • Joining Mainnet
    • Mainnet Upgrades
    • Mainnet Resources
    • Block, Height & State-Sync Source with KSYNC
  • PLANQ | SOURCE Bridge
    • Bridging SRCX from BNB Chain to SOURCE Chain
  • SOURCE MARKET DOCUMENTATION
    • Source Market
    • Introduction
    • sTokens
    • Unitroller
    • USX Controller
    • Governance
  • BRANDING & RESOURCES
    • Social, Resources & Updates
    • Branding
    • Videos
    • How to: MetaMask
    • How to: Keplr
  • Gaming
    • Moochkin's Metarun
      • Rewards and Tournaments
  • LEGAL
    • Disclaimer
    • Privacy Policy
Powered by GitBook
On this page
  • Generate JSON with arguments
  • Instantiate the contract
  1. SMART CONTRACTS & SOURCED DEVELOPMENT
  2. CW-20/ERC-20 Tutorial

Initialize the Contract

Configure and get the contract up-and-running.

Now we've uploaded the contract, now we need to initialise it.

We're using the Poodle Coin example here - $POOD was the first meme coin deployed to a Source Chain testnet.

Choose another name rather than Poodle Coin/POOD, as this is likely already taken on the testnet.

Generate JSON with arguments

To generate the JSON, you can use jq, or, if you're more familiar with JS/node, write a hash and encode it using the node CLI.

This example uses the node REPL. If you have node installed, just type node in the terminal and hit enter to access it.

> const initHash = {
  name: "Poodle Coin",
  symbol: "POOD",
  decimals: 6,
  initial_balances: [
    { address: "<validator-self-delegate-address>", amount: "12345678000"},
  ]
};
< undefined
> JSON.stringify(initHash);
< '{"name":"Poodle Coin","symbol":"POOD","decimals":6,"initial_balances":[{"address":"<validator-self-delegate-address>","amount":"12345678000"}]}'

Instantiate the contract

Note that if you use rich types like CosmWasm's Uint128 then they will be strings from the point of view of JSONSchema. If you have an int, you do not need quotes, e.g. 1 - but for a Uint128 you will need them, e.g. "1".

Note also that the --amount is used to initialize the new account associated with the contract.

In the example below, 6 is the value of $CODE_ID.

sourced tx wasm instantiate 6 \
    '{"name":"Poodle Coin","symbol":"POOD","decimals":6,"initial_balances":[{"address":"<validator-self-delegate-address>","amount":"12345678000"}]}' \
    --amount 50000usource  --label "Poodlecoin erc20" --from <your-key> --chain-id <chain-id> --gas-prices 0.1usource --gas auto --gas-adjustment 1.3 -b block -y

If you have set $CODE_ID in your shell, you can instead run:

sourced tx wasm instantiate $CODE_ID \
    '{"name":"Poodle Coin","symbol":"POOD","decimals":6,"initial_balances":[{"address":"<validator-self-delegate-address>","amount":"12345678000"}]}' \
    --amount 50000usource  --label "Poodlecoin erc20" --from <your-key> --chain-id <chain-id> --gas-prices 0.1usource --gas auto --gas-adjustment 1.3 -b block -y

If this succeeds, look in the output and get contract address from output e.g source1a2b.... or run:

CONTRACT_ADDR=$(sourced query wasm list-contract-by-code $CODE_ID --output json | jq -r '.contracts[0]')

This will allow you to query using the value of $CONTRACT_ADDR

sourced query wasm contract $CONTRACT_ADDR

Note that although we omit --admin when instantiating, in almost all production situations you will want to specify an admin address for the contract. if you do not do this, you will not be able to migrate the contract in future.

PreviousDownload, Compile, StoreNextQuery and run commands

Last updated 2 years ago