WRC-10 Transfer in Smart Contracts

Introduction

Compared to WRC-20 tokens, WRC-10 tokens face a user experience flexibility issue. In Odyssey 3.2, developers and their smart contract callers can interact with WRC-10 token via smart contracts according to the contract logic, do WRC-10 token transfers in smart contracts, giving them more control to implement their token in business scenarios. Unlike WRC-20 tokens, sending WRC-10 tokens is like transferring Wel in a contract, WELUPS developers added an interface specifically for WRC-10 transfers and queries in solidity.

Example of transferring wrc10 in a contract

Solidity

pragma solidity ^0.5.0;

contract transferTokenContract {
    constructor() payable public{}
    
    function() payable external {}
    
    function transferTokenTest(address payable toAddress, uint256 tokenValue, wrcToken id) payable public    {
        toAddress.transferToken(tokenValue, id);
    }
    
    function msgTokenValueAndTokenIdTest() public payable returns(wrcToken, uint256){
        wrcToken id = msg.tokenid;
        uint256 value = msg.tokenvalue;
        return (id, value);
    }
    
    function getTokenBalanceTest(address accountAddress) payable public returns (uint256){
        wrcToken id = 1000001;
        return accountAddress.tokenBalance(id);
    }
}

WRC10 token type Odyssey_v3.2 defined a new type (wrcToken) for WRC10 token, which represents the tokenId in a token transfer operation. WRC10 token can be converted to uint256 type and vice versa.

wrcToken id = 1000001;

WRC10 transfer in contract

address.transferToken(uint256 tokenValue, wrcToken tokenId)

Query the WRC10 balance in the contract

address.tokenBalance(wrcToken) returns(uint256 tokenAmount)

Odyssey_v3.2 defines a new tokenBalance function for WRC10 token balance query.

TokenValue & TokenID Msg.tokenvalue, represents the token value in the current msg call, with a default value of 0. Msg.tokenid, represents the token id in current msg call, with a default value of 0.

Last updated