Builders Guide
Application Development
Smart Contracts
Solidity Guide

Developing Smart Contracts with Solidity

Solidity is the primary language for developing smart contracts on the GOAT Network. This guide will walk you through the process of writing, testing, and deploying Solidity contracts on Testnet3 and Alpha Mainnet.

Prerequisites

  • Solidity Compiler: Install solc or use an IDE like Remix or Visual Studio Code with Solidity extensions.
  • Node.js and NPM: For using development frameworks like Truffle or Hardhat.
  • Wallet Setup: Configure MetaMask or another wallet with Testnet3 and Alpha Mainnet settings.

Writing Your First Contract

Here's a simple HelloWorld contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HelloWorld {
    string public greeting = "Hello, GOAT Network!";

    function setGreeting(string memory _greeting) public {
        greeting = _greeting;
    }
}

Configuring Hardhat

  1. Initialize Hardhat Project:

    npx hardhat init
  2. Install Dependencies:

    npm install --save-dev @nomiclabs/hardhat-ethers ethers
  3. Update hardhat.config.js:

    require('@nomiclabs/hardhat-ethers');
    
    module.exports = {
      defaultNetwork: 'goat',
      networks: {
        goat: {
          url: 'https://rpc.testnet3.goat.network',
          chainId: 48816,
          accounts: ['YOUR_PRIVATE_KEY'],
        },
        alpha: {
          url: 'https://rpc.goat.network',
          chainId: 2345,
          accounts: ['YOUR_PRIVATE_KEY'],
        },
      },
      solidity: {
        version: '0.8.0',
      },
    };

Deploying Your Contract

Create a deployment script:

async function main() {
  const HelloWorld = await ethers.getContractFactory('HelloWorld');
  const hello = await HelloWorld.deploy();

  console.log('Contract deployed to:', hello.address);
}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

Deploy the contract to either testnet3 or alpha mainnet:

npx hardhat run scripts/deploy.js --network goat

or...

npx hardhat run scripts/deploy.js --network alpha

Interacting with the Contract

Use ethers.js within your scripts or front-end application:

const provider = new ethers.providers.JsonRpcProvider('https://rpc.testnet3.goat.network');
const signer = provider.getSigner();
const helloWorldContract = new ethers.Contract(CONTRACT_ADDRESS, ABI, signer);
 
// Get the greeting
const greeting = await helloWorldContract.greeting();
console.log(greeting);
 
// Set a new greeting
const tx = await helloWorldContract.setGreeting('Hello, Testnet3!');
await tx.wait();

Testing Your Contract

Create tests using Hardhat's testing framework:

const { expect } = require('chai');

describe('HelloWorld Contract', function () {
  it('Should return the initial greeting', async function () {
    const HelloWorld = await ethers.getContractFactory('HelloWorld');
    const hello = await HelloWorld.deploy();
    await hello.deployed();

    expect(await hello.greeting()).to.equal('Hello, GOAT Network!');
  });

  it('Should update the greeting', async function () {
    const HelloWorld = await ethers.getContractFactory('HelloWorld');
    const hello = await HelloWorld.deploy();
    await hello.deployed();

    await hello.setGreeting('Hello, Testnet3!');
    expect(await hello.greeting()).to.equal('Hello, Testnet3!');
  });
});

Run tests:

npx hardhat test

Best Practices

  • Security Audits: Always audit your contracts or have them reviewed.
  • Use SafeMath: Although Solidity 0.8.x has built-in overflow checks, be cautious with arithmetic operations.
  • Gas Optimization: Write efficient code to reduce gas costs, leveraging EIP-1559 where applicable.
  • Documentation: Comment your code for better maintainability.

Additional Resources

Contract Addresses

Testnet3 Core Protocol Contracts

Contract NameTestnet3 AddressDescription
WrappedGoatBitcoin.sol0xbC10000000000000000000000000000000000000 (opens in a new tab)Native wrapped Bitcoin token on GOAT Network
GoatDAO.sol0xBC10000000000000000000000000000000000Da0 (opens in a new tab)Governance contract for the GOAT Network
GoatToken.sol0xbC10000000000000000000000000000000000001 (opens in a new tab)Native utility token of the GOAT Network
GoatFoundation.sol0xBc10000000000000000000000000000000000002 (opens in a new tab)Treasury and foundation management
Bridge.sol0xBC10000000000000000000000000000000000003 (opens in a new tab)Cross-chain bridge implementation
Locking.sol0xbC10000000000000000000000000000000000004 (opens in a new tab)Token locking and staking mechanism
Bitcoin.sol0xbc10000000000000000000000000000000000005 (opens in a new tab)Bitcoin block header verification
Relayer.sol0xBC10000000000000000000000000000000000006 (opens in a new tab)Network message relayer
LockingTokenFactory.sol0xBc10000000000000000000000000000000000007 (opens in a new tab)Factory for creating new locking tokens

Alpha Mainnet Core Protocol Contracts

Contract NameMainnet AddressDescription
WGBTC0xbC10000000000000000000000000000000000000 (opens in a new tab)Native wrapped Bitcoin token
Bitcoin.sol0xbc10000000000000000000000000000000000005 (opens in a new tab)Bitcoin block header verification
Multicall30xcA11bde05977b3631167028862bE2a173976CA11 (opens in a new tab)Multicall aggregator
Permit20x000000000022D473030F116dDEE9F6B43aC78BA3 (opens in a new tab)Gasless approvals
Bridge0xBC10000000000000000000000000000000000003 (opens in a new tab)Cross-chain bridge
Locking0xbC10000000000000000000000000000000000004 (opens in a new tab)Token locking mechanism
GOAT Token0xbC10000000000000000000000000000000000001 (opens in a new tab)Native utility token

Alpha Mainnet is now live! For complete contract addresses and integrations, visit our Contracts Reference.